DataTypeAttribute 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 DataTypeAttribute 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| DataTypeAttribute(DataType) |
使用指定的類型名稱初始化該類別的新 DataTypeAttribute 實例。 |
| DataTypeAttribute(String) |
透過使用指定的欄位範本名稱初始化類別的新實例 DataTypeAttribute 。 |
DataTypeAttribute(DataType)
使用指定的類型名稱初始化該類別的新 DataTypeAttribute 實例。
public:
DataTypeAttribute(System::ComponentModel::DataAnnotations::DataType dataType);
public DataTypeAttribute(System.ComponentModel.DataAnnotations.DataType dataType);
new System.ComponentModel.DataAnnotations.DataTypeAttribute : System.ComponentModel.DataAnnotations.DataType -> System.ComponentModel.DataAnnotations.DataTypeAttribute
Public Sub New (dataType As DataType)
參數
- dataType
- DataType
要與資料欄位關聯的類型名稱。
範例
以下範例說明如何使用 DataTypeAttribute(DataType) 建構子指定資料欄位的替代型別。
// Add type information.
[DataType(DataType.EmailAddress)]
public object EmailAddress;
' Add type information.
<DataType(DataType.EmailAddress)> _
Public EmailAddress As Object
備註
名稱是由列舉定義 System.ComponentModel.DataAnnotations.DataType 的其中一個數值。
適用於
DataTypeAttribute(String)
透過使用指定的欄位範本名稱初始化類別的新實例 DataTypeAttribute 。
public:
DataTypeAttribute(System::String ^ customDataType);
public DataTypeAttribute(string customDataType);
new System.ComponentModel.DataAnnotations.DataTypeAttribute : string -> System.ComponentModel.DataAnnotations.DataTypeAttribute
Public Sub New (customDataType As String)
參數
- customDataType
- String
用來關聯資料欄位的自訂欄位範本名稱。
例外狀況
customDataType 是 null 空字串(“”)。
備註
此方法提供了使用屬性 UIHintAttribute 的替代方案。