我如何动态读取类XmlTypeAttribute以获取命名空间? [英] How can I dynamically read a classes XmlTypeAttribute to get the Namespace?
本文介绍了我如何动态读取类XmlTypeAttribute以获取命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从以下类读取 XmlTypeAttribute
,以获取命名空间
值:
< System.CodeDom.Compiler.GeneratedCodeAttribute(wsdl,2.0.50727.42),_
System.SerializableAttribute(),_
System.Diagnostics.DebuggerStepThroughAttribute(),_
System.ComponentModel.DesignerCategoryAttribute(code),_
System.Xml.Serialization.XmlTypeAttribute ([Namespace]:=http://webservices.micros.com/ows/5.1/Availability.wsdl)> _
部分公共类AvailabilityRequest
Inherits AvailRequestSegmentList
私有summaryOnlyField作为布尔
私有xsnField As System.Xml.Serialization.XmlSerializerNamespaces
'''< comentarios />
< System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property summaryOnly()As Boolean
Get
返回Me.summaryOnlyField
End Get
设置
Me.summaryOnlyField = value
结束设置
结束属性
使用以下代码,我可以获得系统的值。 SerializableAttribute但我不能检索有关XmlTypeAttribute的信息。
var ar = typeof(AvailabilityRequest).GetType
ar.GetCustomAttributes(true);
更新2011.12.29
以下代码现在可以使用:
var xmlAttribute =(XmlTypeAttribute)Attribute.GetCustomAttribute(
typeof (AvailabilityRequest),
typeof(XmlTypeAttribute)
);
XNamespace ns = xmlAttribute.Namespace;
ns.NamespaceName.Should()。Be.EqualTo(http://webservices.micros.com/ows/5.1/Availability.wsdl);
解决方案
Attribute类有一个名为GetCustomAttribute的静态方法。 p>
这是用法:
XmlTypeAttribute xmlAttribute =(XmlTypeAttribute)Attribute.GetCustomAttribute (
typeof(theType),
typeof(XmlTypeAttribute)
);
XNamespace ns = xmlAttribute.Namespace;
I need to read the XmlTypeAttribute
from the following class, to get the Namespace
value:
<System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://webservices.micros.com/ows/5.1/Availability.wsdl")> _
Partial Public Class AvailabilityRequest
Inherits AvailRequestSegmentList
Private summaryOnlyField As Boolean
Private xsnField As System.Xml.Serialization.XmlSerializerNamespaces
'''<comentarios/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property summaryOnly() As Boolean
Get
Return Me.summaryOnlyField
End Get
Set
Me.summaryOnlyField = value
End Set
End Property
With the following code, I can get a value for the System.SerializableAttribute but I cannot retrieve information about XmlTypeAttribute.
var ar = typeof (AvailabilityRequest).GetType();
ar.GetCustomAttributes(true);
Update 2011.12.29
The following code now works:
var xmlAttribute = (XmlTypeAttribute)Attribute.GetCustomAttribute(
typeof(AvailabilityRequest),
typeof(XmlTypeAttribute)
);
XNamespace ns = xmlAttribute.Namespace;
ns.NamespaceName.Should().Be.EqualTo("http://webservices.micros.com/ows/5.1/Availability.wsdl");
解决方案
The Attribute class has static method called GetCustomAttribute.
Here's the usage:
XmlTypeAttribute xmlAttribute = (XmlTypeAttribute)Attribute.GetCustomAttribute(
typeof(theType),
typeof(XmlTypeAttribute)
);
XNamespace ns = xmlAttribute.Namespace;
这篇关于我如何动态读取类XmlTypeAttribute以获取命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文