private void AddComparisonValidator <T>(T attr, Type type, PropertyInfo prop, Func <object, IComparisonValidator> ctor1Fun, Func <Func <object, object>, MemberInfo, IComparisonValidator> ctor2Fun) where T : ComparisonAttribute { if (attr == null) { return; } IComparisonValidator propValidator = null; if (attr.CompareToValue != null) { propValidator = ctor1Fun(attr.CompareToValue); } if (attr.ComparsionProperty != null) { if (propValidator != null) { AddAttributePropertyValidator(propValidator, prop, attr.IncludePropertyName); } var propInfo = type.GetProperty(attr.ComparsionProperty); if (propInfo == null) { throw new ArgumentException(string.Format("ComparisonProperty '{0}' of {1} in type '{2}' was not found", attr.ComparsionProperty, typeof(T), type)); } Func <object, object> fun = propInfo.GetValue; propValidator = ctor2Fun(fun, propInfo); } AddAttributePropertyValidator(propValidator, prop, attr.IncludePropertyName); }
private IComparisonValidator CreateComparisonValidator <T>( T attr, Type type, PropertyInfo prop, Func <object, IComparisonValidator> ctor1Fun, Func <Func <object, object>, MemberInfo, IComparisonValidator> ctor2Fun) where T : ComparisonAttribute { if (attr == null) { return(null); } IComparisonValidator propValidator = null; if (attr.CompareToValue != null) { return(ctor1Fun(attr.CompareToValue)); } if (attr.ComparsionProperty != null) { var propInfo = type.GetProperty(attr.ComparsionProperty); if (propInfo == null) { throw new ArgumentException($"ComparisonProperty '{attr.ComparsionProperty}' of {typeof(T)} in type '{type}' was not found"); } Func <object, object> fun = propInfo.GetValue; propValidator = ctor2Fun(fun, propInfo); } return(propValidator); //AddAttributePropertyValidator(propValidator, prop, attr.IncludePropertyName); }