为什么XSD.EXE产生XS字符串属性:整数? [英] Why does xsd.exe generate string property for xs:integer?
问题描述
当我从XSD.EXE XSD模式生成C#类我觉得这behaivor有点怪异
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"/>
生成到:
is generated to:
[System.Xml.Serialization.XmlElementAttribute(DataType="integer", Order=5)]
public string InvoiceNo
{
...
}
这是为什么物业不作为的 INT 而不是<强产生>字符串
Why is that property not generated as an int instead of string?
推荐答案
此行为是的设计:
XS:整数
类型被指定为与结合在其大小没有上限或下限
的数。出于这个原因,既不是XML序列化,也不
验证其映射到 System.Int32 类型。相反,XML序列
映射的xs:整数
为字符串,同时验证其映射到
小数类型是比任何在
的.NET Framework
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 Schema定义标准中定义的数据类型的详细列表。
这篇关于为什么XSD.EXE产生XS字符串属性:整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!