共用方式為


XmlTypeAttribute 類別

定義

控制當屬性目標由 XmlSerializer串行化時所產生的 XML 架構。

public ref class XmlTypeAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct)]
public class XmlTypeAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct)>]
type XmlTypeAttribute = class
    inherit Attribute
Public Class XmlTypeAttribute
Inherits Attribute
繼承
XmlTypeAttribute
屬性

範例

以下範例展示了 應用 XmlTypeAttribute 於兩個類別。

[XmlType(Namespace = "http://www.cpandl.com",
TypeName = "GroupMember")]
public class Person
{
   public string Name;
}

[XmlType(Namespace = "http://www.cohowinery.com",
TypeName = "GroupAddress")]
public class Address
{
   public string Line1;
   public string Line2;
   public string City;
   public string State;
   public string Zip;
}

public class Group
{
   public Person[] Staff;
   public Person Manager;
   public Address Location;
}
<XmlType(Namespace := "http://www.cpandl.com", _
 TypeName := "GroupMember")> _
Public Class Person
    Public Name As String
End Class

<XmlType(Namespace := "http://www.cohowinery.com", _
 TypeName := "GroupAddress")> _ 
Public Class Address
    
    Public Line1 As String
    Public Line2 As String
    Public City As String
    Public State As String
    Public Zip As String
End Class

Public Class Group
    Public Staff() As Person
    Public Manager As Person
    Public Location As Address
End Class

備註

屬於 XmlTypeAttribute 一組屬性,控制物件如何 XmlSerializer 序列化或反序列化。 如需類似屬性的完整清單,請參閱 控制 XML 串行化的屬性

你可以將 套 XmlTypeAttribute 用到 類別、結構、枚舉或介面宣告。

將 套用 XmlTypeAttribute 到 類別,以指定 XML 型別的命名空間、XML 型別名稱,以及是否包含該型別於 XML 結構文件中。 要查看設定類別屬性 XmlTypeAttribute 的結果,請將你的應用程式編譯為可執行檔或 DLL,並將產生的檔案傳入 XML 架構定義工具(Xsd.exe)。 工具會撰寫結構,包括型別定義。

備註

如果你將屬性設 IncludeInSchemafalseXML 架構定義工具(Xsd.exe) 就不會在結構中包含該型別。 預設情況下,對於每個公開類別,XSD 工具會產生該類型的 a complexType 和 a 元素。

欲了解更多屬性的使用資訊,請參閱屬性。

備註

你可以在程式碼中使用這個詞 XmlType ,而不是較長 XmlTypeAttribute的 。

建構函式

名稱 Description
XmlTypeAttribute()

初始化 XmlTypeAttribute 類別的新執行個體。

XmlTypeAttribute(String)

初始化該類別的新實例 XmlTypeAttribute ,並指定 XML 型別的名稱。

屬性

名稱 Description
AnonymousType

取得或設定一個值,用以判斷產生的結構型態是否為 XSD 匿名型態。

IncludeInSchema

取得或設定一個值,指示是否要在 XML 架構文件中包含該型別。

Namespace

取得或設定 XML 型別的命名空間。

TypeId

在衍生類別中實作時,取得這個 Attribute的唯一標識碼。

(繼承來源 Attribute)
TypeName

取得或設定 XML 型別的名稱。

方法

名稱 Description
Equals(Object)

傳回值,這個值表示這個實例是否等於指定的物件。

(繼承來源 Attribute)
GetHashCode()

傳回這個實例的哈希碼。

(繼承來源 Attribute)
GetType()

取得目前實例的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

明確介面實作

名稱 Description
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取 物件的型別資訊,可用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱