Прочетете на английски Редактиране

Споделяне чрез


DataTypeAttribute Constructors

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Initializes a new instance of the DataTypeAttribute class.

Overloads

DataTypeAttribute(DataType)

Initializes a new instance of the DataTypeAttribute class by using the specified type name.

DataTypeAttribute(String)

Initializes a new instance of the DataTypeAttribute class by using the specified field template name.

DataTypeAttribute(DataType)

Source:
DataTypeAttribute.cs
Source:
DataTypeAttribute.cs
Source:
DataTypeAttribute.cs

Initializes a new instance of the DataTypeAttribute class by using the specified type name.

C#
public DataTypeAttribute(System.ComponentModel.DataAnnotations.DataType dataType);

Parameters

dataType
DataType

The name of the type to associate with the data field.

Examples

The following example shows how to use the DataTypeAttribute(DataType) constructor to specify an alternative type for a data field.

C#
// Add type information.
[DataType(DataType.EmailAddress)]
public object EmailAddress;

Remarks

The name is one of the values that are defined by the System.ComponentModel.DataAnnotations.DataType enumeration.

Applies to

.NET 10 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1 (package-provided)
UWP 10.0

DataTypeAttribute(String)

Source:
DataTypeAttribute.cs
Source:
DataTypeAttribute.cs
Source:
DataTypeAttribute.cs

Initializes a new instance of the DataTypeAttribute class by using the specified field template name.

C#
public DataTypeAttribute(string customDataType);

Parameters

customDataType
String

The name of the custom field template to associate with the data field.

Exceptions

customDataType is null or an empty string ("").

Remarks

This method provides an alternative to using the UIHintAttribute attribute.

Applies to

.NET 10 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1 (package-provided)
UWP 10.0