protected IMPropertyInfo GetPropertyInfo(IMPropertyField pField) { if (pField.Property == null && pField.PropertyType == null) { return(new MEmptyPropertyInfo()); } var pi = ReflectionHelper.GetIMPropertyInfo(Model.GetType(), pField.Property, pField.PropertyType); if (pi.PropertyType == null) { pi.PropertyType = pField.PropertyType ?? throw new InvalidOperationException($"Could not find type for {pField.Property}. Please specify it"); } if (pi is MPropertyExpandoInfo ei) { ei.Attributes = pField.Attributes; } if (pField.Attributes != null) { pi.SetAttributes(pField.Attributes); } return(pi); }
private void ValidateField(IMPropertyField pField) { var propInfo = GetPropertyInfo(pField); PropertyInfo oriPropInfo = null; var isExpando = typeof(IDictionary <string, object>).IsAssignableFrom(ModelType); if (!isExpando) { oriPropInfo = ModelType.GetProperty(propInfo.Name); } var fieldIdentifier = mEditContext.Field(propInfo.Name); bool messagesCleared = false; //if attribute is passed via field and not handled by DataAnnotationsValidator foreach (ValidationAttribute attribute in propInfo.GetAttributes().Where(a => a is ValidationAttribute)) { if ((oriPropInfo != null && oriPropInfo.GetCustomAttribute(attribute.GetType()) == null) || isExpando) { if (!messagesCleared) { mValidationMessageStore.Clear(fieldIdentifier); messagesCleared = true; } var value = propInfo.GetValue(Model); if (!attribute.IsValid(value)) { string displayname = propInfo.GetDisplayName(L, false); var msg = attribute.FormatErrorMessage(displayname); mValidationMessageStore.Add(fieldIdentifier, msg); } } } }