Going a bit further than s7orm's answer, I wrote this simple function that I got from reflection on xsd.exe:
private void ExtractXsdFromType(Type type, FileInfo xsd) { XmlReflectionImporter importer = new XmlReflectionImporter(); XmlTypeMapping mapping = importer.ImportTypeMapping(type); XmlSchemas xmlSchemas = new XmlSchemas(); XmlSchemaExporter xmlSchemaExporter = new XmlSchemaExporter(xmlSchemas); using (FileStream fs = xsd.Create()) { xmlSchemaExporter.ExportTypeMapping(mapping); xmlSchemas[0].Write(fs); } }
source share