Skip to content

Instantly share code, notes, and snippets.

@einarwh
Created February 12, 2013 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einarwh/4770394 to your computer and use it in GitHub Desktop.
Save einarwh/4770394 to your computer and use it in GitHub Desktop.
Overview of the MkayAttribute.
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class MkayAttribute : ValidationAttribute, IClientValidatable
{
private readonly string _ruleSource;
private readonly string _defaultErrorMessage;
private readonly Lazy<ConsCell> _cell;
public MkayAttribute(string ruleSource)
{
_ruleSource = ruleSource;
_defaultErrorMessage = "Respect '{0}', mkay?".With(ruleSource);
_cell = new Lazy<ConsCell>(() => new ExpParser(ruleSource).Parse());
}
protected ConsCell Tree
{
get { return _cell.Value; }
}
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(
ModelMetadata metadata, ControllerContext context) ...
protected override ValidationResult IsValid(
object value, ValidationContext validationContext) ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment