SoapServices.GetInteropFieldTypeAndNameFromXmlAttribute 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從 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)
參數
- xmlAttribute
- String
欄位型別的 XML 屬性名稱。
- xmlNamespace
- String
欄位型別的 XML 命名空間。
例外狀況
立即呼叫端沒有基礎結構使用權限。
範例
下列程式碼範例會顯示如何使用這個方法。 此程式代碼範例是提供給 類別之較大範例的 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 命名空間,目前的方法會傳回實際的 Common Language Runtime 功能變數名稱和欄位類型。 然後,.NET Framework 會使用此資訊,以從 XML 數據流讀取的數據填入該欄位。