public static object GetValueForProperty(PropertyMetaData property, object item, UrlHelper url) { object value; if (property.Control() == Controls.Select) { var foreignType = property.ForeignType(); var foreignMetaData = MetaDataProvider.Get( foreignType); object foreignValue = null; if (property.ForeignInfo() != null) { foreignValue = item.GetValue(property.ForeignInfo().Name); } else { var id = item.GetValue(property.Name); if (id != null) { foreignValue = DynamicRepository.GetByPK(foreignType, id); } } Contract.NotNull(new { foreignMetaData }, new { foreignType }); if (!foreignMetaData.IsReadOnly()) { value = new ListVM.EntityLink( foreignValue, foreignMetaData, url); } else { value = GetDisplay(foreignValue); } } else { var metaData = MetaDataProvider.Get(item.GetType()); if (metaData.DisplayProperty() != null && property.Name == metaData.DisplayProperty().Name) { value = new ListVM.EntityLink(item, metaData, url); } else { var propertyValue = property.Info.GetValue(item); if (property.GetAttribute <FullLengthStringDisplayAttribute>() != null) { value = propertyValue.NotNullString(); } else { value = GetDisplay(propertyValue); if (property.Format() != null) { value = value.NotNullString(property.Format()); } } } } return(value); }
public static bool IsReadOnly(this PropertyMetaData propertyMetaData) { return(propertyMetaData.GetAttribute <ReadOnlyAttribute>() != null || !propertyMetaData.Info.CanWrite); }