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 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) 。 该工具写入架构,包括类型定义。

注意

如果将 属性设置为 IncludeInSchemafalse,则 XML 架构定义工具 (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)

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于

另请参阅