Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Classes Generated with XSD.exe Custom Class Names

Tags:

c#

.net

xsd.exe

Is it possible to have any control over the class names that get generated with the .Net XSD.exe tool?

like image 749
Steve Horn Avatar asked Mar 14 '09 20:03

Steve Horn


People also ask

What is XSD exe?

The XML Schema Definition (Xsd.exe) tool generates XML schema or common language runtime classes from XDR, XML, and XSD files, or from classes in a runtime assembly.

What is the use of XSD file in C#?

XSD can easily define parent-child relationship and basic type restrictions needed to define tables - so can be used as database schema. "MSDataSetGenerator" is the "custom tool" that builds whatever files/binaries are needed from the XSD whenever XSD is saved.


2 Answers

As far as I'm aware I don't think this is possible, the class names match almost exactly to whats in the schema.

Personally I would change the class names after XSD has generated the code, but to be honest I usually just stick with what XSD generates. Its then easier for someone else reading the code to understand what classes map to what parts of the XML.

Alternatively, if you have control over the schema you could update that?

like image 111
KevB Avatar answered Nov 07 '22 04:11

KevB


Basically, no. If you were writing the classes manually, you could have:

[XmlType("bar")]
class Foo {}

however, you can't do this with the xsd-generated classes. Unfortunately, one of the things you can't do with a partial class is rename it. Of course, you could use xsd to generate it, change the .cs file and don't generate it again, but that is not ideal for maintenance.

like image 38
Marc Gravell Avatar answered Nov 07 '22 03:11

Marc Gravell