I have a problem with Serialization and Deserialization of an object. I have an object Foo with different properties and some of the properties have the attribute NonSerialized. I have some cases when I want to serialize the fields and to read the serialized object with all the fields. Is this possible to do?
Asked
Active
Viewed 193 times
0
-
2Have you tried writing your own wrapper around the object, and marking the properties as Serialized there? – Callum Bradbury Sep 30 '15 at 11:04
-
1Duplicate of http://stackoverflow.com/questions/11880666/net-serialization-how-to-selectively-ignore-data-fields or http://stackoverflow.com/questions/3648858/conditional-c-sharp-binary-serialization – dbc Sep 30 '15 at 19:04
1 Answers
0
If you have control over the class Foo
you could use the ShouldSerialize
attribute to control whether the field should be serialized. For a idea how it works you can look here Xml serialization - Hide null values
-
-
Well, in this case the only thing I could think of is implementing `ISerializable` ... which is no fun =), or as Callum said, wrap it – DerApe Sep 30 '15 at 11:41