Reputation: 8968
Is it possible to have any control over the class names that get generated with the .Net XSD.exe tool?
Upvotes: 13
Views: 8015
Reputation: 1841
Any schema with somewhat deep nesting then ends up with utterly useless names.
I don't know of a way to work around the problem, but my tip to at least reduce the negative impact is this: Define a list of aliases for the awfully-named types. This way you can write code that isn't completely unreadable without losing the ability to regenerate.
using AgentAddress = Example.Namespace.DataContract.RootElementNestedElementAgentAddress; ...
It's a pity this list itself has to be copy-pasted to all code files needing it, but I think this at least constitutes an improvement.
Upvotes: 4
Reputation: 3690
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?
Upvotes: 6
Reputation: 1062510
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.
Upvotes: 7