为什么 xsd.exe 会为 xs:integer 生成字符串属性?

4

本文介绍了为什么 xsd.exe 会为 xs:integer 生成字符串属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

当我使用 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 the xs: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 生成字符串属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14