XmlTypeAttribute 類別

定義

控制由 XmlSerializer 序列化屬性 (Attribute) 目標後所產生的 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 ref class Person
{
public:
   String^ Name;
};


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

public ref class Group
{
public:
   array<Person^>^Staff;
   Person^ Manager;
   Address^ Location;
};
[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) 。 此工具會寫入架構,包括型別定義。

注意

如果您將 IncludeInSchema 屬性設定為 falseXML 架構定義工具 (Xsd.exe) 不包含架構中的類型。 根據預設,針對每個公用類別,XSD 工具會產生 complexType 和 該類型的 專案。

如需使用屬性的詳細資訊,請參閱 屬性

注意

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

建構函式

XmlTypeAttribute()

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

XmlTypeAttribute(String)

初始化 XmlTypeAttribute 類別的新執行個體,並指定 XML 型別的名稱。

屬性

AnonymousType

取得或設定值,判斷產生的結構描述型別是否為 XSD 匿名型別。

IncludeInSchema

取得或設定值,指出是否將型別包含在 XML 結構描述文件中。

Namespace

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

TypeId

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

(繼承來源 Attribute)
TypeName

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

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

明確介面實作

_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)

適用於

另請參閱