bianbian coding life

便便代码人生: 关注技术, 翻译文档, 偶尔动动手

[原] C#泛型实现流中C/C++格式的struct数据的通用读取方法

Posted by bianbian on 2009-03-02 09:26


本文Tags: , , ,

背景简单提一下:好多个C/C++构成的结构体(struct)数据需要在C#中读取,他们可能在文件中或网络中(总之有办法转为流Stream)。
在C#中用Marshal的PtrToStructure()可以实现byte[]向struct的转变。
不过如果每个struct都要写个方法也太低效了,尤其是我现在遇到几十个struct的情况。。。。
研究了一下泛型(C#2.0就支持了),发现方法泛型可以解决这个问题。
Read the rest of this entry »

标签: , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C#, Technology | 2 Comments »