共用方式為


ValidationContext Class

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

Provides information about a type or member to validate.

Inheritance Hierarchy

System.Object
  System.ComponentModel.DataAnnotations.ValidationContext

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

Syntax

'Declaration
Public NotInheritable Class ValidationContext _
    Implements IServiceProvider
public sealed class ValidationContext : IServiceProvider

The ValidationContext type exposes the following members.

Constructors

  Name Description
Public method ValidationContext(Object) Initializes a new instance of the ValidationContext class with the specified object to validate.
Public method ValidationContext(Object, IDictionary<Object, Object>) Initializes a new instance of the ValidationContext class with the specified object to validate and a collection of values related to validation.
Public method ValidationContext(Object, IServiceProvider, IDictionary<Object, Object>) Initializes a new instance of the ValidationContext class with the specified object to validate, a service provider that enables validation methods to access external services, and a collection of values related to validation.

Top

Properties

  Name Description
Public property DisplayName Gets or sets the name to display to users for the member to validate.
Public property Items Gets the collection of values associated with the validation request.
Public property MemberName Gets or sets the programmatic name of the member to validate.
Public property ObjectInstance Gets the object to validate.
Public property ObjectType Gets the type of the object to validate.

Top

Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetService Retrieves an instance of the service to use during validation.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method InitializeServiceProvider Initializes the ValidationContext with a service provider that can return service instances of the specified type when the GetService method is called.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

The ValidationContext class describes the type or member on which validation is performed. It also enables validation routines to reference services that are available through the GetService method of the IServiceProvider interface.

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.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.