private void ProcessValidationAttribute(AttributeEntityClassPair pair) { // check if the attribute specifies a method for retrieving additional rules var a = (ValidationAttribute)pair.Attribute; if (string.IsNullOrEmpty(a.HighLevelRulesProviderMethod)) { return; } // find method on class (use the class that declared the attribute, not the entityClass) const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly; var method = pair.DeclaringClass.GetMethod(a.HighLevelRulesProviderMethod, bindingFlags); // validate method signature if (method == null) { throw new InvalidOperationException(string.Format("Method {0} not found on class {1}", a.HighLevelRulesProviderMethod, pair.DeclaringClass.FullName)); } if (method.GetParameters().Length != 0 || !typeof(IValidationRuleSet).IsAssignableFrom(method.ReturnType)) { throw new InvalidOperationException(string.Format("Method {0} must have 0 parameters and return IValidationRuleSet", a.HighLevelRulesProviderMethod)); } var ruleSet = (IValidationRuleSet)method.Invoke(null, null); _highLevelRules.Add(ruleSet); }
private void ProcessEntityAttribute(AttributeEntityClassPair pair) { // TODO: this could be changed to a dictionary of delegates, or a visitor pattern of some kind if (pair.Attribute is UniqueKeyAttribute) { ProcessUniqueKeyAttribute(pair); } if (pair.Attribute is ValidationAttribute) { ProcessValidationAttribute(pair); } }
private void ProcessUniqueKeyAttribute(AttributeEntityClassPair pair) { var uka = (UniqueKeyAttribute)pair.Attribute; _lowLevelRules.Add(new UniqueKeySpecification(pair.DeclaringClass, uka.LogicalName, uka.MemberProperties)); }
private void ProcessEntityAttribute(AttributeEntityClassPair pair) { // TODO: this could be changed to a dictionary of delegates, or a visitor pattern of some kind if (pair.Attribute is UniqueKeyAttribute) ProcessUniqueKeyAttribute(pair); if (pair.Attribute is ValidationAttribute) ProcessValidationAttribute(pair); }
private void ProcessValidationAttribute(AttributeEntityClassPair pair) { // check if the attribute specifies a method for retrieving additional rules var a = (ValidationAttribute)pair.Attribute; if (string.IsNullOrEmpty(a.HighLevelRulesProviderMethod)) return; // find method on class (use the class that declared the attribute, not the entityClass) const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly; var method = pair.DeclaringClass.GetMethod(a.HighLevelRulesProviderMethod, bindingFlags); // validate method signature if (method == null) throw new InvalidOperationException(string.Format("Method {0} not found on class {1}", a.HighLevelRulesProviderMethod, pair.DeclaringClass.FullName)); if (method.GetParameters().Length != 0 || !typeof(IValidationRuleSet).IsAssignableFrom(method.ReturnType)) throw new InvalidOperationException(string.Format("Method {0} must have 0 parameters and return IValidationRuleSet", a.HighLevelRulesProviderMethod)); var ruleSet = (IValidationRuleSet)method.Invoke(null, null); _highLevelRules.Add(ruleSet); }