private static List <SelectListItem> GetSelectedListItems( PropertyMetaData property, System.Collections.IEnumerable source) { var result = new List <SelectListItem>(); var relatedPropertyType = property.ForeignType(); var foreignMetaData = MetaDataProvider.Get(relatedPropertyType); var first = true; PropertyInfo propertyInfo = null; foreach (var o in source) { object id; if (first) { propertyInfo = o.GetType().GetProperty(property.Info.Name); first = false; } if (propertyInfo != null) { id = o.GetValue(property.Info.Name); } else { id = o.GetValue(LinqToSqlUtils.GetPKPropertyName( foreignMetaData.EntityType)); } result.Add(new SelectListItem { Text = GetDisplay(o, foreignMetaData).ToString(), Value = id.ToString() }); } return(result.OrderBy(sli => sli.Text).ToList()); }
public virtual void Initialize(IMetaDataProvider metaDataService) { MetaDataProvider = metaDataService; MetaData = MetaDataProvider.Get(typeof(T)); Validator = (ICmsValidator <T>)AllValidators.List.GetValueOrDefault(typeof(T)); }