Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XmlAttributeAttribute数据类型属性?_C#_Xml_Reflection - Fatal编程技术网

C# XmlAttributeAttribute数据类型属性?

C# XmlAttributeAttribute数据类型属性?,c#,xml,reflection,C#,Xml,Reflection,我还没有找到任何关于这方面的确切文件,也没有太多的问题;在使用XmlAttributeAttribute时,是否需要使用DataType=“string”而不是typeof(string)?例如: XmlAttribute("Description", DataType = "string") XmlAttribute("Description", typeof(string)) 上面两行代码都可以编译;但是,当使用typeof(string)方法时,我得到一个错误,说不能指定基元类型(这可能

我还没有找到任何关于这方面的确切文件,也没有太多的问题;在使用
XmlAttributeAttribute
时,是否需要使用
DataType=“string”
而不是
typeof(string)
?例如:

XmlAttribute("Description", DataType = "string")
XmlAttribute("Description", typeof(string))
上面两行代码都可以编译;但是,当使用
typeof(string)
方法时,我得到一个错误,说不能指定基元类型(这可能与类和重写属性的嵌套有关吗?)

如果同时删除
数据类型
,由于某种原因,反射会失败,构建也不会成功


是我做错了什么,还是这就是我的本意?如果要求使用
DataType
方法,那么如何指定自定义类型,例如
enum

数据类型
用于
xsd
命名空间中的简单类型,例如
string
。对于复杂类型,可以指定
XmlAttributeAttribute
Type
属性。因此,由于
xsd:string
xsd
名称空间中的一个简单类型,因此使用

[XmlAttribute("Name", DataType = "string")]
如前所述,如果您有一个自定义枚举,您会这样做

[XmlAttribute("Name", typeof(MyEnum))]

这就是问题所在;然而,有两件事。1.我不得不删除枚举的类型规范(不知道为什么)。2.我不确定为什么这会导致编译时错误而不是运行时错误。