I leveraging the XmlSerializer to convert to/from XML. Here is an example class:
[XmlRootAttribute('myClass')] public class MyClass { private string someField; [XmlElement('someField')] public string SomeField { get { return someField; } set { someField = value; } } }
The XML would look like the following:
<myClass> <someField>Some Value</someField> </myClass>
I want to be able to add an attribute to this class. For example, sometimes I need to add change tracking to the element. An attribute, say ‘IdRef’, would be added to the myClass element.
<myClass t:IdRef='someGuid' xmlns:t='uri:some:uri'> <someField>SomeValue</someField> </myClass>
I’m hoping to keep the IdRef attribute out of the main POCO class. Also, since there are many classes like the one above, so I’m hoping not to have to create a subclass for each one, adding the extended attribute. Maybe creating a custom implementation using the IXmlSerializer interface?
UPDATE I’m going with the simple solution described below. I think I was trying to ‘over think’ this implementation and adding complexity where it wasn’t needed.
What do I think? I think you’ll have to stick them in your ‘POCO’ class, but you can hide them away in a region labeled something like ‘extra serialization markup properties’ and use other attributes to make them mostly invisible to consumers of your class.