简体   繁体   English

大型机平面文件到C#类

[英]Mainframe Flat file to C# classes

I have to communicate with a IBM main frame using IBM WebSphere. 我必须使用IBM WebSphere与IBM主机通信。 The service on the main frame side can only use flat files. 主机侧的服务只能使用平面文件。

On my side I want to use CQRS (Command / Query) 在我这边,我想使用CQRS(命令/查询)

In other words I want to serialize command / queries and deserialize query results 换句话说,我想序列化命令/查询并反序列化查询结果

I could do it with standard reflection offcourse, but my question is if there is a nicer way of doing it? 我可以在标准反射场上做到这一点,但是我的问题是,是否有更好的方法呢?

Can I make use of dynamics? 我可以利用动力吗?

Flatfile > ParsedObjectStructured > Dynamic type > static type

This would depend an awful lot on what the format of the flat file is, and how the schema works - is it self-describing, for example? 这将取决于哪些平面文件的格式是一个可怕很多 ,并且架构是如何工作的-它是自描述的,例如? However, it sounds to me like most of the work here would be in understanding the flat-file format (and the schema-binding). 但是,在我看来,这里的大部分工作都是在了解平面文件格式(以及架构绑定)中。 From there, the choice of "deserialize into the static type" vs "deserialize into a dynamic type" is kinda moot, and I would say that there is very little point deserializing into a dynamic type just to have to map it all to the static type. 从那里开始,选择“反序列化为静态类型”还是“反序列化为动态类型”有点儿争议,我想说的是,将反序列化为动态类型的一点点就是必须将所有内容都映射到静态类型类型。 Additionally, the static type can (again, depending on the file-format specifics) be a handy place to decorate the types to say "here's how to interpret this", if the file-format needs specification. 此外,静态类型可以 (再次,根据文件格式的细节)是装饰类型说“这里是如何解读这个”,如果文件格式需要规范一个方便的地方。 For example (and I'm totally making this up as I go along - don't expect this to relate to your format): 例如(随着我的前进,我将完全弥补这一点-不要指望这与您的格式有关):

[Frobber(Offset = 4, Format = DataFormat.LittleEndianInt32)]
public int Id {get;set;}

[Frobber(Offset = 0, Format = DataFormat.LittleEndianInt32)]
public int Index {get;set;}

[Frobber(Offset = 8, Format = DataFormat.FixedAscii, Size = 20)]
public string Name {get;set;}

[Frobber(Offset = 28, Format = DataFormat.Blob)] // implicit Size=16 as Guid
public Guid UniqueKey {get;set;}

where FrobberAttribute is just something you might invent to specify the file format. 您可能会发明FrobberAttribute来指定文件格式。 Of course, if the schema is defined internally to the file, this may not be necessary. 当然,如果架构是在文件内部定义的,则可能没有必要。

Re reflection: basic reflection will work fine if the data is fairly light usage; 重新反射:如果数据使用量很少,则基本反射会很好; but overall, reflection can be quite expensive. 但总的来说,反射可能会非常昂贵。 If you need it to be optimal , you would probably want the implementation to consider strategy-caching (ie only doing the discovery work once) and meta-programming (turning the strategy into ready-baked IL, rather than incurring the overhead of reflection at runtime). 如果您需要使其达到最佳 ,则可能希望实现考虑策略缓存(即仅执行一次发现工作)和元编程(将策略转换为现成的IL),而不是在以下位置产生反射开销运行)。

If the file format is a common / popular one, you might find that there are existing tools for reading that format. 如果文件格式是常见/流行的文件格式,则可能会发现已有读取该格式的工具。 If not, you can either roll your own, or find some crazy person who enjoys writing serialization and meta-programming tools. 如果没有,您可以自己动手,也可以找一些喜欢写序列化和元编程工具的疯子。 Such people do exist... 这样的人确实存在...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM