我正在使用优秀的OpenIso8583Net来发送/接收ISO消息。但是,由于每个组织都有自己的定义和定制,所以我希望能够尽可能少接触项目的源代码来定制格式,以便能够更容易地升级到新版本。
下面是我现在面临的三种定制:
Bitmap使用AsciiFormatter而不是BinaryFormatter?由于位图是AMessage类的私有字段,所以即使我直接从AMessage派生出一个新的自定义类,也无法访问它。构造函数默认使用BinaryFormatter。目前,我已经修改了Bitmap.cs无参数构造函数以使用AsciiFormatter。AsciiFormatter。但我希望它能使用BcdFormatter。我已经修改了这个部分,使其在默认情况下在BcdFormatter中使用VariableLengthFormatter。
如果有人向我展示了通过扩展而不是修改来处理这些自定义的更好的方法,我将不胜感激。Fields部分显示的内容。现在,我必须公开Template属性,并使用以下代码片段: for (var i= 2;i如何在不公开Template的情况下访问字段?为了日志记录目的,我希望访问主程序中字段的Display方法。
发布于 2012-02-17 10:40:07
我刚刚对这个项目做了一些修改,允许这样做。从0.5.0版开始(更新您的NuGet包)
位图格式化程序
您可以在模板中为您的消息类设置位图格式化程序。下面是一些示例代码:
public class AsciiIsoMsg : Iso8583
{
// First you need to customise the template
// The message
private static readonly Template template;
static AsciiIsoMsg()
{
// Get the default template for the Iso8583 class
template = GetDefaultIso8583Template();
// change the bitmap formatter
template.BitmapFormatter = new AsciiFormatter();
}
// override the base class using the template and you will be using the bitmap formatter
public AsciiIsoMsg():base(template)
{
}
}字段的设置长度格式化程序
在static AsciiIso()方法中,如果以这种方式进行修改,将更改字段2以使用BCD长度格式化程序:
// Set field 2 to use BCD formatter
template[2] = FieldDescriptor.BcdVar(2, 19, Formatters.Bcd);日志文件
若要在日志文件中显示消息,请在消息类上使用.ToString()方法。
var msg = new AsciiIsoMsg();
msg.MessageType = Iso8583.MsgType._0200_TRAN_REQ;
msg[3] = "010000";
Console.WriteLine(msg.ToString());这意味着:
0200:
[Fixed n 6 0006] 003 [010000]https://stackoverflow.com/questions/9266951
复制相似问题