public static bool IsEditionInfoCompleted(object edition, EditionInfoType infoType) { foreach (var prop in edition.GetType().GetProperties()) { var attrs = prop.GetCustomAttributes <EditionFieldAttribute>(true).ToList(); if (attrs.Any()) { var editionField = attrs.First(); if ((editionField.InfoType == infoType || infoType == EditionInfoType.AllInfo) && editionField.Required) { var propType = prop.PropertyType; //if (!IsSimpleType(propType)) // continue; var propVal = prop.GetValue(edition); var underlyingPropType = prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>) ? Nullable.GetUnderlyingType(prop.PropertyType) : null; if (propVal == null) { return(false); } if (propType == typeof(string) && string.IsNullOrWhiteSpace((string)propVal)) { return(false); } if (propVal.Equals(propType.GetDefaultValue())) { return(false); } if (underlyingPropType != null && propVal.Equals(underlyingPropType.GetDefaultValue())) { return(false); } } } } return(true); }
public EditionFieldAttribute(EditionInfoType infoType, bool required = true) { InfoType = infoType; Required = required; }
bool IsEditionTranslationInfoCompleted(EditionTranslationEntity editionTranslationEntity, EditionInfoType infoType) { return(EditionServiceHelper.IsEditionInfoCompleted(editionTranslationEntity, infoType)); }