/// <summary> /// Return object property from child class. /// </summary> /// <param name="item"></param> /// <returns></returns> public object GetProperty(object item) { try { var typedItem = (T)item; var func = PropertyExpression.Compile(); return(func(typedItem)); } catch (InvalidCastException) { var propName = ExpressionHelper.GetPropertyName(PropertyExpression); var property = item.GetType().GetProperty(propName); if (property == null) { throw new InvalidCastException($"Member {propName} not present on source."); } return(property.GetValue(item, null)); } }
public override async IAsyncEnumerable <ValidationFailure> ValidateAsync(TModel model, ValidationContext context) { var propGetter = PropertyExpression.Compile(); var propVal = propGetter(model); bool valid = false; try { valid = await IsValid(model, propVal); } catch (Exception) { } if (!valid) { yield return(Failure(PropertyExpression, ErrorTemplate, context)); } }