SoapServices.GetInteropFieldTypeAndNameFromXmlAttribute 方法

定义

从 XML 特性名、命名空间和包含对象的 Type 中检索字段类型。

public:
 static void GetInteropFieldTypeAndNameFromXmlAttribute(Type ^ containingType, System::String ^ xmlAttribute, System::String ^ xmlNamespace, [Runtime::InteropServices::Out] Type ^ % type, [Runtime::InteropServices::Out] System::String ^ % name);
public static void GetInteropFieldTypeAndNameFromXmlAttribute (Type containingType, string xmlAttribute, string xmlNamespace, out Type type, out string name);
static member GetInteropFieldTypeAndNameFromXmlAttribute : Type * string * string * Type * string -> unit
Public Shared Sub GetInteropFieldTypeAndNameFromXmlAttribute (containingType As Type, xmlAttribute As String, xmlNamespace As String, ByRef type As Type, ByRef name As String)

参数

containingType
Type

包含该字段的对象的 Type

xmlAttribute
String

该字段类型的 XML 特性名。

xmlNamespace
String

该字段类型的 XML 命名空间。

type
Type

此方法返回时,包含该字段的 Type。 此参数未经初始化即被传递。

name
String

此方法返回时,包含保存该字段名的 String。 此参数未经初始化即被传递。

例外

直接调用方没有基础结构权限。

示例

下面的代码示例演示如何使用此方法。 此代码示例是为 SoapServices 类提供的一个更大示例的一部分。

// Get the name and the type of the field using its XML
// element name and its XML namespace. For this query to work,
// the containing type must be preloaded, and the XML element
// name and the XML namespace must be explicitly declared on
// the field using a SoapFieldAttribute.
// Preload the containing type.
SoapServices::PreLoad( ExampleNamespace::ExampleClass::typeid );

// Get the name and the type of a field that will be
// serialized as an XML element.
Type^ containingType = ExampleNamespace::ExampleClass::typeid;
String^ xmlElementNamespace = L"http://example.org/ExampleFieldNamespace";
String^ xmlElementName = L"ExampleFieldElementName";
Type^ fieldType;
String^ fieldName;
SoapServices::GetInteropFieldTypeAndNameFromXmlElement(
   containingType,xmlElementName,xmlElementNamespace,fieldType,fieldName );
Console::WriteLine( L"The type of the field is {0}.", fieldType );
Console::WriteLine( L"The name of the field is {0}.", fieldName );

// Get the name and the type of a field that will be
// serialized as an XML attribute.
String^ xmlAttributeNamespace =
   L"http://example.org/ExampleAttributeNamespace";
String^ xmlAttributeName = L"ExampleFieldAttributeName";
SoapServices::GetInteropFieldTypeAndNameFromXmlAttribute(
   containingType,xmlAttributeName,xmlAttributeNamespace,fieldType,fieldName );
Console::WriteLine( L"The type of the field is {0}.", fieldType );
Console::WriteLine( L"The name of the field is {0}.", fieldName );
// Get the name and the type of the field using its XML 
// element name and its XML namespace. For this query to work,
// the containing type must be preloaded, and the XML element 
// name and the XML namespace must be explicitly declared on 
// the field using a SoapFieldAttribute.

// Preload the containing type.
SoapServices.PreLoad(typeof(ExampleNamespace.ExampleClass));

// Get the name and the type of a field that will be 
// serialized as an XML element.
Type containingType = typeof(ExampleNamespace.ExampleClass);
string xmlElementNamespace = 
    "http://example.org/ExampleFieldNamespace";
string xmlElementName = "ExampleFieldElementName";
Type fieldType;
string fieldName;
SoapServices.GetInteropFieldTypeAndNameFromXmlElement(
    containingType, xmlElementName, xmlElementNamespace, 
    out fieldType, out fieldName);
Console.WriteLine(
    "The type of the field is {0}.",
    fieldType);
Console.WriteLine(
    "The name of the field is {0}.",
    fieldName);

// Get the name and the type of a field that will be 
// serialized as an XML attribute.
string xmlAttributeNamespace = 
    "http://example.org/ExampleAttributeNamespace";
string xmlAttributeName = "ExampleFieldAttributeName";
SoapServices.GetInteropFieldTypeAndNameFromXmlAttribute(
    containingType, xmlAttributeName, xmlAttributeNamespace, 
    out fieldType, out fieldName);
Console.WriteLine(
    "The type of the field is {0}.",
    fieldType);
Console.WriteLine(
    "The name of the field is {0}.",
    fieldName);

注解

给定包含对象的类型以及由.NET Framework读取的 XML 属性和 XML 命名空间,当前方法将返回字段的实际公共语言运行时字段名称和类型。 然后,.NET Framework使用此信息用从 XML 流中读取的数据填充该字段。

适用于