DataContractAttribute.Name 属性

定义

获取或设置类型的数据协定的名称。Gets or sets the name of the data contract for the type.

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

属性值

String

数据协定的本地名称。The local name of a data contract. 默认值是应用了该属性的类的名称。The default is the name of the class that the attribute is applied to.

注解

Name 属性用于为数据协定指定名称,该名称也将成为 XML 架构中类型的名称。The Name property is used to give a name to a data contract, which is the name of the type in XML schema. 有关详细信息,请参阅 数据协定名称For more information, see Data Contract Names.

默认情况下,数据协定的名称是应用了 DataContractAttribute 的类型的名称。By default, the name of a data contract is the name of the type that the DataContractAttribute is applied to. 不过,可能出于某些原因更改此默认名称。However, there may be reasons to change this default name. 其中一个原因就是使现有类型可以处理必须符合现有数据协定的数据。One reason is to allow an existing type to process data that must conform to an existing data contract. 例如,有一个名为 Person 的类型,但包含在某个 XML 架构中的数据协定要求该名称为 CustomerFor example, there exists a type named Person but the data contract, embodied in an XML schema, requires that the name be Customer. 可通过将该属性值设置为 Customer 来满足该协定。The contract can be satisfied by setting the property value to Customer.

另一个原因是允许生成不能作为类型名的名称。A second reason is to allow the generation of names that are invalid as type names. 例如,如果数据协定需要一个不允许作为类型名的名称,则将该属性值设置为这一不允许使用的名称。For example, if a data contract demands a name that is not allowable as a type name, set the property value to that disallowed name. 例如,不允许使用字符串“$value”作为类型名,但允许使用它作为 Name 属性值。For instance, the string "$value" is disallowed as a type name but is allowed as a Name property value.

适用于