There is two ways to make properties non-serializable in.NET using attributes.
You may set attributes [NonSerialized]
or [XmlIgnore]
If you serializing in binary or SOAP you should use [NonSerialized]
, if you want to serialize just in XML you should use [XmlIgnore]
.
So in your case the answer is [XmlIgnore]
EDIT:
There is no way to apply attributes to properties dynamically.
Here some info about that here: Can attributes be added dynamically in C#? and here Remove C# attribute of a property dynamically
Also as a workout you may have different copies of your class with different attributes.
OR
Have a copy of your class set all props as serializable but populate only properties you need, this way every thing else will be null/empty and after serialization of that class you should get the XML you need.