语言

DataContractAttribute.Name 属性

定义

获取或设置类型的数据协定的名称。

public:
 property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public string Name { get; set; }
public string? Name { get; set; }
member this.Name : string with get, set
Public Property Name As String

属性值

数据协定的本地名称。 默认值是应用特性的类的名称。

注解

该 Name 属性用于为数据协定指定名称,该协定是 XML 架构中类型的名称。 有关详细信息,请参阅 数据协定名称。

默认情况下,数据协定的名称是应用于的类型 DataContractAttribute 的名称。 但是,可能有理由更改此默认名称。 一个原因是允许现有类型处理必须符合现有数据协定的数据。 例如,存在一种名为Person但数据协定(在 XML 架构中体现)的类型需要名称。Customer 通过将属性值设置为 Customer.,可以满足协定。

第二个原因是允许生成作为类型名称无效的名称。 例如,如果数据协定要求不允许作为类型名称的名称,请将属性值设置为不允许的名称。 例如,不允许字符串“$value”作为类型名称,但允许作为 Name 属性值。

适用于