/// <include file='doc\ListBindingHelper.uex' path='docs/doc[@for="ListBindingHelper.GetListItemProperties2"]/*' /> public static PropertyDescriptorCollection GetListItemProperties(object dataSource, string dataMember, PropertyDescriptor[] listAccessors) { dataSource = GetList(dataSource); if (!string.IsNullOrEmpty(dataMember)) { // Find the property on the data source specified by the data member PropertyDescriptorCollection dsProps = ListBindingHelper.GetListItemProperties(dataSource); PropertyDescriptor dmProp = dsProps.Find(dataMember, true); // Error: Property not found - data member is invalid if (dmProp == null) { throw new System.ArgumentException(string.Format(SR.DataSourceDataMemberPropNotFound, dataMember)); } // Add the data member property to the list accessors int len = (listAccessors == null) ? 1 : (listAccessors.Length + 1); PropertyDescriptor[] listAccessors2 = new PropertyDescriptor[len]; listAccessors2[0] = dmProp; for (int i = 1; i < len; ++i) { listAccessors2[i] = listAccessors[i - 1]; } // Replace old accessors with new accessors listAccessors = listAccessors2; } return(GetListItemProperties(dataSource, listAccessors)); }
void ResetList() { if (!is_initialized) { return; } IList l; object source = ListBindingHelper.GetList(datasource, datamember); // // If original source is null, then create a new object list // Otherwise, try to infer the list item type // if (datasource == null) { l = new BindingList <object>(); //list_defaulted = true; } else if (source == null) { //Infer type based on datasource and datamember, // where datasource is an empty IEnumerable // and need to find out the datamember type Type property_type = ListBindingHelper.GetListItemProperties(datasource) [datamember].PropertyType; Type t = typeof(BindingList <>).MakeGenericType(new Type [] { property_type }); l = (IList)Activator.CreateInstance(t); } else if (source is IList) { l = (IList)source; } else if (source is IEnumerable) { IList new_list = GetListFromEnumerable((IEnumerable)source); l = new_list == null ? list : new_list; } else if (source is Type) { Type t = typeof(BindingList <>).MakeGenericType(new Type [] { (Type)source }); l = (IList)Activator.CreateInstance(t); } else { Type t = typeof(BindingList <>).MakeGenericType(new Type[] { source.GetType() }); l = (IList)Activator.CreateInstance(t); l.Add(source); } SetList(l); }
/// <include file='doc\ListBindingHelper.uex' path='docs/doc[@for="ListBindingHelper.GetList2"]/*' /> public static object GetList(object dataSource, string dataMember) { // // The purpose of this method is to find a list, given a 'data source' object and a // decription of some 'data member' property of that object which returns the list. // // - If the data source is not a list, we get the list by just querying for the // current value of that property on the data source itself. // // - If the data source is a list, we have to first pick some item from that list, // then query for the value of that property on the individual list item. // dataSource = GetList(dataSource); if (dataSource == null || dataSource is Type || string.IsNullOrEmpty(dataMember)) { return(dataSource); } PropertyDescriptorCollection dsProps = ListBindingHelper.GetListItemProperties(dataSource); PropertyDescriptor dmProp = dsProps.Find(dataMember, true); if (dmProp == null) { throw new System.ArgumentException(string.Format(SR.DataSourceDataMemberPropNotFound, dataMember)); } object currentItem; if (dataSource is ICurrencyManagerProvider) { // Data source is another BindingSource so ask for its current item CurrencyManager cm = (dataSource as ICurrencyManagerProvider).CurrencyManager; bool currentKnown = (cm != null && cm.Position >= 0 && cm.Position <= cm.Count - 1); currentItem = currentKnown ? cm.Current : null; } else if (dataSource is IEnumerable) { // Data source is an enumerable list, so walk to the first item currentItem = GetFirstItemByEnumerable(dataSource as IEnumerable); } else { // Data source is not a list, so just use the data source itself currentItem = dataSource; } // Query the data member property on the chosen object to get back the list return((currentItem == null) ? null : dmProp.GetValue(currentItem)); }
void ResetDataMemberIfInvalid() { if (datamember == String.Empty) { return; } // if dataMember doesn't refer to a valid property of dataSource, we need to reset it var property = ListBindingHelper.GetListItemProperties(datasource).Find(datamember, true); if (property == null) { datamember = String.Empty; OnDataMemberChanged(EventArgs.Empty); } }
void SetList(IList l) { if (list is IBindingList) { ((IBindingList)list).ListChanged -= IBindingListChangedHandler; } list = l; item_type = ListBindingHelper.GetListItemType(list); item_has_default_ctor = item_type.GetConstructor(Type.EmptyTypes) != null; list_is_ibinding = list is IBindingList; if (list_is_ibinding) { ((IBindingList)list).ListChanged += IBindingListChangedHandler; if (list is IBindingListView) { ((IBindingListView)list).Filter = filter; } } ResetBindings(true); }
public virtual string GetListName(PropertyDescriptor[] listAccessors) { return(ListBindingHelper.GetListName(list, listAccessors)); }
public virtual PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors) { return(ListBindingHelper.GetListItemProperties(list, listAccessors)); }
internal override PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors) { return(ListBindingHelper.GetListItemProperties(_dataSource, listAccessors)); }
public override PropertyDescriptorCollection GetItemProperties() { return(ListBindingHelper.GetListItemProperties(list)); }