2014-11-02 43 views
0

我使用xml2code庫將xsd文件轉換爲C#代碼。xml2code lib從`positiveInteger`生成`string`類型

Generator.xs文件,下面的代碼被映射XSD類型到C#類型:

var importer = new XmlSchemaImporter(schemas, generationOptions, new ImportContext(new CodeIdentifiers(), false)); 

foreach (XmlSchemaType type in xsd.Items.OfType<XmlSchemaType>()) 
{ 
    var mapping = importer.ImportSchemaType(type.QualifiedName); 
    exporter.ExportTypeMapping(mapping); 
} 

所有類型映射相當好,除了positiveInteger(來自命名空間 「http://www.w3.org/2001/XMLSchema」)。

我試圖從代碼修復,財產以後這樣的:

switch (mapping.XsdTypeName) 
{ 
    case "positiveInteger": 
     mapping.TypeFullName = "System.UInt32"; // was "System.String" 
     mapping.TypeName = "UInt32";   // was "String" 
     break; 
    default: 
     break; 
} 

但不幸的是所有XmlTypeMapping屬性是隻讀的,所以我不能活動創建一個新的實例發送到功能exporter.ExportTypeMapping()

我不知道如何改變映射類型。

回答

0

看來微軟XmlSchemaImportersd庫(內System.Xml.Serialization),被映射以下類型String

negativeInteger 
nonNegativeInteger 
nonPositiveInteger 
positiveInteger 

如此給力XmlSchemaImportersd映射到你需要使用以下xs:類型C#的基本類型instaed :

byte 
decimal 
int 
integer 
long 
short 
unsignedLong 
unsignedInt 
unsignedShort 
unsignedByte