custom ElementName in generated .cs file

Mar 16, 2011 at 3:45 PM

I have generated some cs files from xsd files. On some property names, i need to override the generated name with [XmlElement(ElementName="MyName")]. While i can put this right into the generated code, they will get lost once re-generated. What is the best practice to have my overrides retained from different generations?



Mar 16, 2011 at 8:03 PM

Generally, partial classes can be convenient for this. They can be defined in separate files and thus won't be overwritten.

Of course you cannot define a property in two partial classes, but maybe you can find another solution to reach your goal.


Alternatively, you could use some automatic transformation on your files, (xslt, T4, batchfile or whatever) which you can then easily repeat for future generations.