C# Class ExpressiveAnnotations.Attributes.ExpressiveAttribute

Inheritance: System.ComponentModel.DataAnnotations.ValidationAttribute
Afficher le fichier Open project: jwaliszko/ExpressiveAnnotations

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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

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

Method Details

Compile() public méthode

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.
Résultat void

Equals() public méthode

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

ExpressiveAttribute() protected méthode

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.
Résultat System

ExpressiveAttribute() protected méthode

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.
Résultat System

FormatErrorMessage() public méthode

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.
Résultat string

FormatErrorMessage() public méthode

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.
Résultat string

GetHashCode() public méthode

Returns a hash code for this instance.
public GetHashCode ( ) : int
Résultat int

GetPriority() public méthode

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

IsValid() protected méthode

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.
Résultat System.ComponentModel.DataAnnotations.ValidationResult

IsValidInternal() protected abstract méthode

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.
Résultat System.ComponentModel.DataAnnotations.ValidationResult

ToString() public méthode

Returns a System.String that represents this instance.
public ToString ( ) : string
Résultat string