System.Windows.Forms.ListBindingHelper.GetList C# (CSharp) Method

GetList() public static method

public static GetList ( object list ) : object
list object
return object
        public static object GetList(object list) {
            if (list is IListSource) {
                return (list as IListSource).GetList();
            }
            else {
                return list;
            }
        }

Same methods

ListBindingHelper::GetList ( object dataSource, string dataMember ) : object

Usage Example

Example #1
0
        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);
        }