2010-05-02 3 views
4

(코드에서) C# 형식의 xsd 스키마를 생성하려면 어떻게해야합니까? xcd 스키마가 wcf에서 datacontracts를 위해 생성되기 때문에 확실한 방법이 있어야합니다.C# 형식의 XSD 스키마 가져 오기

답변

1

그래서, 나는 xsd.exe에 반사경을보고 내 문제에 대한 해결책을 찾을 수 있습니다. 내가 xsd.exe에 반영에서 파생 된이 간단한 함수 작성 s7orm의 대답보다 더 조금가는

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

당신은 XML Schema Definition Tool (xsd.exe)

xsd.exe YourAssembly.dll /type:YourNamespace.YourType 
+0

그래, 나도 알아,하지만 내가 원하는 도구를 통하지 않고 코드로 스키마를 생성합니다. – Krassi

2

: 여기에 나중에 참조 할 수 있도록이다

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); 
     }   
    } 
관련 문제