简体   繁体   English

序列化EntitySet <T> C#

[英]Serialize EntitySet<T> c#

I would like some help with ac# issue. 我想要一些关于ac#问题的帮助。 I have a customer class which has an EntitySet<Book> . 我有一个客户类,它有一个EntitySet<Book> The class is marked Serializable so that I can serialize it with a BinaryFormatter . 该类标记为Serializable以便我可以使用BinaryFormatter对其进行序列化。 The problem is that the EntitySet is not serializable. 问题是EntitySet不可序列化。

I need to serialize it manually with a MemoryStream . 我需要使用MemoryStream手动序列化它。 Does anyone know how to achieve this? 有谁知道如何实现这一目标? A code sample would be great! 代码示例会很棒!

Via the use of reflection you can step over the public and private fields as well as the class name and the parent you inherit from of the instantiated object. 通过使用反射,您可以跨越公共和私有字段以及从实例化对象继承的类名和父级。

Output these values to a string save it to a memorystream which you can read from later and then create a new object with reflection based on the type found. 将这些值输出到一个字符串,将其保存到您可以从以后读取的内存流,然后根据找到的类型创建一个带有反射的新对象。

Currently unable to give a more clear example. 目前无法给出更明确的例子。 But this is one of the many ways to go 但这是许多方法之一

我使用代理序列化程序修复它: https//msdn.microsoft.com/en-us/magazine/cc188950.aspx

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

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