/// <summary> /// Builds the custom rule-set (rules that are specified in an XML format). /// </summary> /// <param name="domainClass"></param> /// <returns></returns> private static ValidationRuleSet BuildCustomRules(Type domainClass) { try { // combine rules from all non-static (i.e. custom) sources var sources = new EntityValidationRuleSetSourceExtensionPoint().CreateExtensions(); var rules = from source in sources.Cast <IValidationRuleSetSource>() where !source.IsStatic let r = source.GetRuleSet(domainClass) where !r.IsEmpty select r; return(new ValidationRuleSet(rules)); } catch (Exception e) { // any exceptions here must be logged and ignored, as their is really no good way to handle them Platform.Log(LogLevel.Error, e, "Error attempting to compile custom validation rules"); return(new ValidationRuleSet()); } }
/// <summary> /// Builds a set of validation rules by processing the attributes defined on the specified entity class. /// </summary> /// <returns></returns> public void BuildRuleSet() { ProcessClassProperties(); // process class-level attributes foreach (var pair in GetClassAttributes(_entityClass)) { ProcessEntityAttribute(pair); } // process external providers of static rules var sources = new EntityValidationRuleSetSourceExtensionPoint().CreateExtensions(); var rules = from source in sources.Cast <IValidationRuleSetSource>() where source.IsStatic let r = source.GetRuleSet(_entityClass) where !r.IsEmpty select r; _highLevelRules.AddRange(rules); _processed = true; }
/// <summary> /// Builds a set of validation rules by processing the attributes defined on the specified entity class. /// </summary> /// <returns></returns> public void BuildRuleSet() { ProcessClassProperties(); // process class-level attributes foreach (var pair in GetClassAttributes(_entityClass)) { ProcessEntityAttribute(pair); } // process external providers of static rules var sources = new EntityValidationRuleSetSourceExtensionPoint().CreateExtensions(); var rules = from source in sources.Cast<IValidationRuleSetSource>() where source.IsStatic let r = source.GetRuleSet(_entityClass) where !r.IsEmpty select r; _highLevelRules.AddRange(rules); _processed = true; }