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; }
member this.Name : string with get, set
Public Property Name As 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.

適用於