Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
3.40/5 (3 votes)
See more:
Hi All,
I hope i am posting in the right forum as i am looking for a .Net related solution rather than a pure XML solution.

I have the following class which i serialise using default XML serialisation.

Class UserA
UserID
UserName
Description
Comments
End Class

Later, my requirements changed and i had to generate 2 views of the same data.
In my 1st view, i would generate XML for the whole object (all 4 properties)
My 2nd view - include only UserID and UserName.

i modified the code as below

Interface iUser
UserID
UserName
End Class

Class UserA
Implements iUser
UserID implements iUser.UserID
UserName implements implements iUser.UserName
Description
Comments
End Class

I intended to serialise appropriate objects (iUser or UserA) based on my view requirements.
Unfortunately, i realised that XML serailisation does not work on interfaces - end to my dreams of getting it easy:(

My question is - if i have an Object instance, can i use any feature with serialisation to generate multiple views of an object?

I have ventured towards creating seperate classes, ISerializable, etc.

looking for suggestions on whats the best way to take this forward.

Thanks in advance.

modified on Thursday, August 13, 2009 4:23 AM
Posted

1 solution

It might be worth bearing in mind that you can implement IXmlSerializable in an object and just dump that into the object hierachy you use the automated serializer for (XmlSerializer). The serializer will call the IXmlSerializable instead of using reflection, which means you could do your branching in there.

However, it could be a maintainance time bomb. ^^

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900