public void Initialize(Attribute attribute) { //Get all parametters of the Attribute: the name and their values. //For example: //In LengthAttribute the parametter are Min and Max. System.Type clazz = attribute.GetType(); IRuleArgs ruleArgs = attribute as IRuleArgs; if (ruleArgs == null) { throw new ArgumentException("Attribute " + clazz + " doesn't implement IRuleArgs interface."); } else { if (ruleArgs.Message == null) { throw new ArgumentException(string.Format("The value of the message in {0} attribute is null (nothing for VB.Net Users). Add some message ", clazz) + "on the attribute to solve this issue. For Example:\n" + "- private string message = \"Error on property Foo\";\n" + "Or you can use interpolators with resources files:\n" + "-private string message = \"{validator.MyValidatorMessage}\";"); } attributeMessage = ruleArgs.Message; } foreach (PropertyInfo property in clazz.GetProperties()) { attributeParameters.Add(property.Name.ToLowerInvariant(), property.GetValue(attribute, null)); } }
public FinalRuleArgsOptions(IRuleArgs constraintAttribute) { if (constraintAttribute == null) { throw new ArgumentNullException("constraintAttribute"); } this.constraintAttribute = constraintAttribute; }
public FinalRuleArgsOptions(IRuleArgs constraintAttribute) { if (constraintAttribute == null) { throw new ArgumentNullException("constraintAttribute"); } this.constraintAttribute = constraintAttribute; }
private IEnumerable<Rule> ConvertToXValRules(IRuleArgs att) { foreach (var rule in ruleEmitters.EmitRules(att)) { if(rule != null) { rule.ErrorMessage = MessageIfSpecified(att.Message); yield return rule; } } }
private IEnumerable <Rule> ConvertToXValRules(IRuleArgs ruleArgs) { foreach (var rule in _ruleEmitters.EmitRules(ruleArgs)) { if (rule != null) { rule.ErrorMessage = MessageIfSpecified(ruleArgs.Message); yield return(rule); } } }
private IEnumerable <string> GetResourceFileValidatorsMessages(ResourceManager manager) { Assembly a = typeof(IRuleArgs).Assembly; foreach (System.Type type in a.GetTypes()) { if (!type.IsAbstract && typeof(IRuleArgs).IsAssignableFrom(type) && type.GetConstructor(new System.Type[0]) != null) { IRuleArgs item = (IRuleArgs)Activator.CreateInstance(type, null, null); if (string.IsNullOrEmpty(item.Message) || item.Message.Length < 2) { continue; } string resName = item.Message.Substring(1, item.Message.Length - 2); yield return(manager.GetString(resName)); } } }
/// <summary> /// The convert to x val rules. /// </summary> /// <param name="ruleArgs"> /// The rule args. /// </param> /// <returns> /// </returns> private IEnumerable<Rule> ConvertToXValRules(IRuleArgs ruleArgs) { foreach (Rule rule in this.ruleEmitters.EmitRules(ruleArgs)) { if (rule != null) { rule.ErrorMessage = MessageIfSpecified(ruleArgs.Message); yield return rule; } } }
public ChainableConstraint(TConstraints parent, IRuleArgs constraintAttribute) : base(parent) { ConstraintAttribute = constraintAttribute; }