DataType Enumeration

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Represents data types that are associated with data properties.

Namespace:  System.ComponentModel.DataAnnotations
Assembly:  System.ComponentModel.DataAnnotations (in System.ComponentModel.DataAnnotations.dll)

Syntax

'Declaration
Public Enumeration DataType
public enum DataType

Members

Member name Description
Custom Represents a data type that is not one of the known types.
DateTime Represents an instant in time, expressed as a date and time of day.
Date Represents a data value.
Time Represents a time value.
Duration Represents a continuous time during which an object exists.
PhoneNumber Represents a phone number value.
Currency Represents a currency value.
Text Represents text that is displayed.
Html Represents an HTML file.
MultilineText Represents multiline text.
EmailAddress Represents an e-mail address.
Password Represents a password value.
Url Represents a URL value.
ImageUrl Represents a URL value that is displayed as an image instead of text.

Remarks

You use the DataType enumeration when you apply the DataTypeAttribute attribute to a property. The DataType enumeration contains valid values you use with the DataTypeAttribute attribute. You use the DataTypeAttribute attribute to specify the type of data that is expected for the property beyond the data type of the property. For example, properties named Phone and EmailAddress may both contain string values, but you can specify the expected values by applying the DataTypeAttribute attribute with the PhoneNumber and EmailAddress values respectively.

Examples

The following example shows how to specify an e-mail address property and a phone number property.

Public Class Customer
  <DataType(DataType.EmailAddress)> _
  Public Property EmailAddress As String
    'Implement Get and Set logic
  End Property

  <DataType(DataType.PhoneNumber)> _
  Public Property Phone As String
    'Implement Get and Set logic
  End Property
End Class
public class Customer
{
  [DataType(DataType.EmailAddress)]
  public string EmailAddress { get; set; }

  [DataType(DataType.PhoneNumber)]
  public string Phone { get; set; }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.