I’m working with an XSD -> C# class parser which generates classes for our data model, which is to be shared between a WPF client and a Silverlight web-based portion.
We are trying to augment the generated classes with [DataContract] attributes that should only be used when the SILVERLIGHT symbol is not defined, i.e.:
#if !SILVERLIGHT
[DataContract]
#endif
public class Class1 { /* ... */ }
How can I add this #if / #endif block to the CodeTypeDefinition of the Class1, or to the CodeAttributeDeclaration of DataContract?
What I’ve actually decided to do is add the
#if / #endiftags through a Python script, after the code file is generated. Robert’s reply is functionally valid, but I just didn’t feel right using two separate classes when one should be just fine.Although it introduces another language into the data model generation, this seems like the cleanest way to get exactly what I want. The script we are using is below. It only needs to check for NonSerializable attributes (specifically, on PropertyChanged events) now because of a new way we structured the data contract.