自定义二进制文件的惯用C#反序列化? [英] Idiomatic C# deserialization of custom binary files?

查看:205
本文介绍了自定义二进制文件的惯用C#反序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,

执行二进制自定义格式的序列化/反序列化的最惯用的方法是什么?例如,您将如何读取具有以字节指定的一组标头(例如4、4、16、4、8、8、8、4、16)且没有填充且整数/byte[]类型混合的文件?

换句话说,在指定结构时如何实现与C中相同的控制级别,而不必求助于Stream上的Read/WriteBytes序列?

谢谢.

解决方案

这是一个文章,它说明了实现此目标的一种方法.但是,如果您要使用意识形态的.NET,则 BinaryReader 是要走的路.如果不强制使用格式,并且可以控制格式,则还可以使用 解决方案

Here's an article which illustrates one method to achieve this. But if you want ideomatic .NET then BinaryReader is the way to go. If the format is not imposed and you have control over it you could also use BinaryFormatter but what it produces is not interoperable.

这篇关于自定义二进制文件的惯用C#反序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆