Hi all, I have a some classes which I need to serialize in two different ways: first- "basic" fields, and the second- some other fields. e.g. a User class which I sometimes need to serialize just the "first name" and "last name" fields, and sometimes I need to serialize the "id" and "email" fields as well.
The best way I found to do this so far is mark the basic fields with the [DataMember] attribute, and let .NET do the serializing for me, and for the rest mark them with a customize attribute and do the serialization myself. This solution proved to be very costly: I first sirialize the basic attributes (as mentioned, .NET does that for me) Then I get the property names of the fields marked with the custom attribute (using reflection namespace), Then I try to get the those fields and their values from the object, and add their serialization to the basic serialization (not very successfully so far).....
Question is: Is there a better way? preferbly by which .NET will do the rest of the work for me, and if not, at least one by which I don't need to go through all the object's fields, find the relevant ones and serialize them myself..
Thank you all..