开发者

Create virtual methods using xsd.exe

I am using classes that were generated from an XML schema using the xsd.exe tool. It currently generates a huge (32k line) .cs file. I then serialize and deserialize parts of the of model using XMLSerializer. I need to override properties in these classes, so I have partial classes in separate files that override some of these generated methods. However, this means going in and marking hundreds of methods as virtual every time the schema changes. Is there a way to get the xsd.exe tool to ma开发者_Go百科rk methods as virtual when they are generated?


The output from XSD.exe is not very customizable.

I had a similar problem a while ago and created a simple console application that modified the generated output from XSD.exe.


It seems odd to me that you need to modify the serialization code. If you need to override properties, can't you simply create new properties that kind of wrap the existing ones yet add new behaviour? Or did I miss the point.


If you have to do this on an ongoing basis, you should look into code generation of some kind. Build the XSD-generated types, then write an application to load those types, and use Reflection to generate types that are identical except that all the properties are virtual. You will then be able to derive from the new types and override the properties as necessary.

This can become part of your build process.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜