C# Class ExpressiveAnnotations.Attributes.ExpressiveAttribute

Inheritance: System.ComponentModel.DataAnnotations.ValidationAttribute
Datei anzeigen Open project: jwaliszko/ExpressiveAnnotations

Public Methods

Method Description
Compile ( Type validationContextType, bool force = false ) : void

Parses and compiles expression provided to the attribute. Compiled lambda is then cached and used for validation purposes.

Equals ( object obj ) : bool

Determines whether the specified System.Object, is equal to this instance.

FormatErrorMessage ( string displayName, string expression, Type objectType, Guid>.IDictionary &fieldsMap ) : string

Formats the error message for client (value indicators not resolved - replaced by guids to be dynamically extracted by client-code).

This method interprets custom format specifiers, provided to error message string, for which values or display names of model fields are extracted. Specifiers should be given in braces (curly brackets), i.e. {fieldPath[:indicator]}, e.g. {field}, {field.field:n}. Braces can be escaped by double-braces, i.e. to output a { use {{ and to output a } use }}.

FormatErrorMessage ( string displayName, string expression, object objectInstance ) : string

Formats the error message for user.

This method interprets custom format specifiers, provided to error message string, for which values or display names of model fields are extracted. Specifiers should be given in braces (curly brackets), i.e. {fieldPath[:indicator]}, e.g. {field}, {field.field:n}. Braces can be escaped by double-braces, i.e. to output a { use {{ and to output a } use }}.

GetHashCode ( ) : int

Returns a hash code for this instance.

GetPriority ( ) : int?

Gets the value of Priority if it has been set, or null.

ToString ( ) : string

Returns a System.String that represents this instance.

Protected Methods

Method Description
ExpressiveAttribute ( string expression, Func errorMessageAccessor ) : System

Constructor for expressive validation attribute.

Allows for providing a resource accessor function that will be used to retrieve the error message. An example would be to have something like, e.g. CustomAttribute() : base( () => MyResources.MyErrorMessage ) {}.

ExpressiveAttribute ( string expression, string errorMessage ) : System

Constructor for expressive validation attribute.

IsValid ( object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext ) : System.ComponentModel.DataAnnotations.ValidationResult

Validates a specified value with respect to the associated validation attribute.

IsValidInternal ( object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext ) : System.ComponentModel.DataAnnotations.ValidationResult

Validates a specified value with respect to the associated validation attribute. Internally used by the ExpressiveAttribute.IsValid(object,System.ComponentModel.DataAnnotations.ValidationContext) method.

Private Methods

Method Description
AdjustMemberName ( System.ComponentModel.DataAnnotations.ValidationContext validationContext ) : void
PreformatMessage ( string displayName, string expression, IList &items ) : string

Method Details

Compile() public method

Parses and compiles expression provided to the attribute. Compiled lambda is then cached and used for validation purposes.
public Compile ( Type validationContextType, bool force = false ) : void
validationContextType System.Type The type of the object to be validated.
force bool Flag indicating whether parsing should be rerun despite the fact compiled lambda already exists.
return void

Equals() public method

Determines whether the specified System.Object, is equal to this instance.
public Equals ( object obj ) : bool
obj object The to compare with this instance.
return bool

ExpressiveAttribute() protected method

Constructor for expressive validation attribute.
Allows for providing a resource accessor function that will be used to retrieve the error message. An example would be to have something like, e.g. CustomAttribute() : base( () => MyResources.MyErrorMessage ) {}.
expression is null
protected ExpressiveAttribute ( string expression, Func errorMessageAccessor ) : System
expression string The logical expression based on which specified condition is computed.
errorMessageAccessor Func The error message accessor, allowing the error message to be provided dynamically.
return System

ExpressiveAttribute() protected method

Constructor for expressive validation attribute.
expression is null
protected ExpressiveAttribute ( string expression, string errorMessage ) : System
expression string The logical expression based on which specified condition is computed.
errorMessage string The error message to associate with a validation control.
return System

FormatErrorMessage() public method

Formats the error message for client (value indicators not resolved - replaced by guids to be dynamically extracted by client-code).
This method interprets custom format specifiers, provided to error message string, for which values or display names of model fields are extracted. Specifiers should be given in braces (curly brackets), i.e. {fieldPath[:indicator]}, e.g. {field}, {field.field:n}. Braces can be escaped by double-braces, i.e. to output a { use {{ and to output a } use }}.
public FormatErrorMessage ( string displayName, string expression, Type objectType, Guid>.IDictionary &fieldsMap ) : string
displayName string The user-visible name of the required field to include in the formatted message.
expression string The user-visible expression to include in the formatted message.
objectType System.Type The annotated field declaring container type.
fieldsMap Guid>.IDictionary The map containing fields names for which values should be extracted by client-side.
return string

FormatErrorMessage() public method

Formats the error message for user.
This method interprets custom format specifiers, provided to error message string, for which values or display names of model fields are extracted. Specifiers should be given in braces (curly brackets), i.e. {fieldPath[:indicator]}, e.g. {field}, {field.field:n}. Braces can be escaped by double-braces, i.e. to output a { use {{ and to output a } use }}.
public FormatErrorMessage ( string displayName, string expression, object objectInstance ) : string
displayName string The user-visible name of the required field to include in the formatted message.
expression string The user-visible expression to include in the formatted message.
objectInstance object The anotated field declaring container instance.
return string

GetHashCode() public method

Returns a hash code for this instance.
public GetHashCode ( ) : int
return int

GetPriority() public method

Gets the value of Priority if it has been set, or null.
public GetPriority ( ) : int?
return int?

IsValid() protected method

Validates a specified value with respect to the associated validation attribute.
protected IsValid ( object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext ) : System.ComponentModel.DataAnnotations.ValidationResult
value object The value to validate.
validationContext System.ComponentModel.DataAnnotations.ValidationContext The validation context.
return System.ComponentModel.DataAnnotations.ValidationResult

IsValidInternal() protected abstract method

Validates a specified value with respect to the associated validation attribute. Internally used by the ExpressiveAttribute.IsValid(object,System.ComponentModel.DataAnnotations.ValidationContext) method.
protected abstract IsValidInternal ( object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext ) : System.ComponentModel.DataAnnotations.ValidationResult
value object The value to validate.
validationContext System.ComponentModel.DataAnnotations.ValidationContext The validation context.
return System.ComponentModel.DataAnnotations.ValidationResult

ToString() public method

Returns a System.String that represents this instance.
public ToString ( ) : string
return string