tags:

views:

144

answers:

2

Hello, how can I generate a xsd schema for a c# type (in code). There must be certainly a way, because xsd schema is generated for datacontracts in wcf.

+1  A: 

You can use the XML Schema Definition Tool (xsd.exe)

xsd.exe YourAssembly.dll /type:YourNamespace.YourType
Thomas Levesque
Yeah I know, but I want to generate the schema in code, not via tool.
s7orm
A: 

So, I found a solution to my problem by looking with reflector in the xsd.exe. Here is it for future reference:

XmlReflectionImporter importer = new XmlReflectionImporter();
XmlTypeMapping stringMapping = importer.ImportTypeMapping(typeof(String));
s7orm