問題描述
當我使用 xsd.exe 從 xsd 架構生成 c# 類時,我發現這種行為有點奇怪.
When I generate a c# class from a xsd schema with xsd.exe I find this behaivor a bit wierd.
我的元素:
<xs:element name="InvoiceNo" type="xs:integer"/>
生成到:
[System.Xml.Serialization.XmlElementAttribute(DataType="integer", Order=5)]
public string InvoiceNo
{
...
}
為什么該屬性沒有生成為 int 而不是 string?
Why is that property not generated as an int instead of string?
推薦答案
這種行為是設計使然一個>:
xs:integer
類型被指定為沒有大小寫的數字受限于它的大小.因此,XML 序列化和驗證將其映射到 System.Int32 類型.相反,XML 序列化將 xs:integer
映射到字符串,而驗證將其映射到Decimal 類型,遠大于.NET 框架
The
xs:integer
type is specified as a number with no upper or lower bound on its size. For this reason, neither XML serialization nor validation map it to the System.Int32 type. Instead, XML serialization maps thexs:integer
to a string while validation maps it to the Decimal type that is much larger than any of the integer types in the .NET Framework
使用 xs:int
,它是一個有符號的 32 位整數,具有 Xsd.exe 將其映射到 System.Int32:
Use xs:int
, which is a signed 32-bit integer, to have Xsd.exe map it to a System.Int32:
<xs:element name="InvoiceNo" type="xs:int" />
這里是 XML 架構定義標準中定義的數據類型的詳細列表.
Here's a detailed list of the data types defined in the XML Schema Definition standard.
這篇關于為什么 xsd.exe 會為 xs:integer 生成字符串屬性?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!