This documentation is archived and is not being maintained.

CustomValidationAttribute.Method Property

Gets the validation method.

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

public string Method { get; }

Property Value

Type: System.String
The name of the validation method.

The custom method specified by this property must be public and static, and it must return a Boolean value. It must also take at least one input parameter that specifies the object to validate. This parameter can be strongly typed. If a process passes a value of a different type, type conversion will be attempted.

The specified method should return true if a given object is valid. Otherwise it should return false.

The custom method can also take parameters that specify a ValidationContext input value and a ValidationResult output value. The ValidationContext parameter provides additional context information that the method can use to determine the context that it is used in. The ValidationResult output parameter enables the method to return an error message.

If the method returns null for the ValidationResult parameter or if it returns an empty value for the ErrorMessage property, the default FormatErrorMessage method will be called to compose the error message.

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.