0

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?

dbc
  • 104,963
  • 20
  • 228
  • 340
vladtamas
  • 51
  • 4
  • 2
    Have you tried writing your own wrapper around the object, and marking the properties as Serialized there? – Callum Bradbury Sep 30 '15 at 11:04
  • 1
    Duplicate 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 Answers1

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

Community
  • 1
  • 1
DerApe
  • 3,097
  • 2
  • 35
  • 55