public static PropertyDescriptorCollection GetSourceProperties(object list)
        {
            ITypedList typedList = list as ITypedList;

            if (typedList != null)
            {
                return(typedList.GetItemProperties(null));
            }
            IList l = list as IList;

            if (l != null && l.Count > 0)
            {
                return(GetItemProperties(l[0]));
            }
            IEnumerable enumerable = list as IEnumerable;

            if (enumerable != null)
            {
                IEnumerator enumerator = enumerable.GetEnumerator();
                if (enumerator.MoveNext())
                {
                    return(GetItemProperties(enumerator.Current));
                }
            }
            return(null);
        }
        /// <include file='doc\DesignTimeData.uex' path='docs/doc[@for="DesignTimeData.GetDataMembers"]/*' />
        /// <devdoc>
        /// </devdoc>
        public static string[] GetDataMembers(object dataSource)
        {
            IListSource listSource = dataSource as IListSource;

            if ((listSource != null) && listSource.ContainsListCollection)
            {
                IList memberList = ((IListSource)dataSource).GetList();
                Debug.Assert(memberList != null, "Got back null from IListSource");

                ITypedList typedList = memberList as ITypedList;
                if (typedList != null)
                {
                    PropertyDescriptorCollection props = typedList.GetItemProperties(new PropertyDescriptor[0]);

                    if (props != null)
                    {
                        ArrayList members = new ArrayList(props.Count);

                        foreach (PropertyDescriptor pd in props)
                        {
                            members.Add(pd.Name);
                        }

                        return((string[])members.ToArray(typeof(string)));
                    }
                }
            }

            return(null);
        }
        PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            PropertyDescriptorCollection propertiesList = NestedTypedList.GetItemProperties(listAccessors);

            propertiesList.Add(descriptor);
            return(propertiesList);
        }
        public PropertyDescriptorCollection GetProperties()
        {
            IList list = DataSource as IList;

            if (list == null)
            {
                if (DataSource is IListSource)
                {
                    list = ((IListSource)DataSource).GetList();
                }
            }

            if (list == null)
            {
                return(new PropertyDescriptorCollection(new PropertyDescriptor[0], true));
            }

            ITypedList typedList = list as ITypedList;

            if (typedList == null)
            {
                if (list.Count > 0)
                {
                    return(TypeDescriptor.GetProperties(list[0]));
                }
            }
            else
            {
                return(typedList.GetItemProperties(new PropertyDescriptor[0]));
            }
            return(new PropertyDescriptorCollection(new PropertyDescriptor[0], true));
        }
        PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            PropertyDescriptorCollection props = null;
            ITypedList srcTypedList            = dataSource as ITypedList;

            if (srcTypedList != null)
            {
                props = srcTypedList.GetItemProperties(listAccessors);
            }
            if (dataSource.Count > 0)
            {
                props = TypeDescriptor.GetProperties(dataSource[0]);
            }
            if (props == null)
            {
                return(null);
            }

            List <PropertyDescriptor> res = new List <PropertyDescriptor>();

            switch (rtype)
            {
            case ReportType.Report1:
                res.Add(props["A"]);
                break;

            case ReportType.Report2:
                res.Add(props["B"]);
                break;
            }

            return(new PropertyDescriptorCollection(res.ToArray()));
        }
Example #6
0
        private bool InitBindableControls(Control control)
        {
            foreach (Binding binding in control.DataBindings)
            {
                BizEntity item = binding.BindingManagerBase.Current as BizEntity;

                if (item != null)
                {
                    string key = GetBindingKey(item, binding, control);

                    if (_keyToControl.ContainsKey(key))
                    {
                        continue;
                    }

                    string[]           str = null;
                    PropertyDescriptor pd  = null;

                    ITypedList typedList = binding.DataSource as ITypedList;

                    if (typedList != null)
                    {
                        pd = typedList.GetItemProperties(null).Find(
                            binding.BindingMemberInfo.BindingField, false);

                        if (pd != null)
                        {
                            str = Validator.GetErrorMessages(item, pd);
                        }
                    }

                    if (str == null)
                    {
                        str = item.GetErrorMessages(binding.BindingMemberInfo.BindingField);
                    }

                    if (str.Length > 0)
                    {
                        Array.Sort(str);
                    }

                    ControlInfo ci = new ControlInfo(control, str.Length > 0, pd);

                    _bindableControls.Add(ci);
                    _keyToControl.Add(key, ci);

                    if (ci.IsValidatable)
                    {
                        _toolTip.SetToolTip(control, string.Join("\r\n", str));
                    }

                    control.LostFocus      += ValidateControl;
                    control.Validated      += ValidateControl;
                    control.EnabledChanged += ValidateControl;
                }
            }

            return(true);
        }
Example #7
0
        private void button2_Click(object sender, EventArgs e)
        {
            ITypedList   tList = (ITypedList)((IListSource)dataGrid1.DataSource).GetList();
            IBindingList bList = (IBindingList)tList;

            int index = bList.Find(tList.GetItemProperties(null)[0], "Stephen");

            dataGrid1.Rows[index].Selected = true;
        }
Example #8
0
        public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor [] listAccessors)
        {
            ITypedList typed = source as ITypedList;

            if (typed == null)
            {
                return(null);
            }
            return(typed.GetItemProperties(listAccessors));
        }
Example #9
0
        public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            List <PropertyDescriptor> result = new List <PropertyDescriptor>();

            foreach (PropertyDescriptor pd in NestedTypedList.GetItemProperties(ExtractOriginalDescriptors(listAccessors)))
            {
                result.Add(new EmptyObjectPropertyDescriptor(pd, _DateFields));
            }
            return(new PropertyDescriptorCollection(result.ToArray()));
        }
Example #10
0
        public static IEnumerable ResolveDataSource(object o, string data_member)
        {
            IEnumerable ds;

            ds = o as IEnumerable;

            if (ds != null)
            {
                return(ds);
            }

            IListSource ls = o as IListSource;

            if (ls == null)
            {
                return(null);
            }

            IList member_list = ls.GetList();

            if (!ls.ContainsListCollection)
            {
                return(member_list);
            }

            ITypedList tl = member_list as ITypedList;

            if (tl == null)
            {
                return(null);
            }

            PropertyDescriptorCollection pd = tl.GetItemProperties(new PropertyDescriptor[0]);

            if (pd == null || pd.Count == 0)
            {
                throw new HttpException("The selected data source did not contain any data members to bind to");
            }

            PropertyDescriptor member_desc = data_member == "" ?
                                             pd[0] :
                                             pd.Find(data_member, true);

            if (member_desc != null)
            {
                ds = member_desc.GetValue(member_list[0]) as IEnumerable;
            }

            if (ds == null)
            {
                throw new HttpException("A list corresponding to the selected DataMember was not found");
            }

            return(ds);
        }
Example #11
0
 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
 {
     if (DataView == null)
     {
         ITypedList typedList = (ITypedList)_dataView;
         return(typedList.GetItemProperties(new PropertyDescriptor[0]));
     }
     else
     {
         return(DataView.Table.GetPropertyDescriptorCollection());
     }
 }
        private PropertyDescriptor GetPropertyDescriptorFromITypedList(ITypedList iTypedList)
        {
            if (string.IsNullOrEmpty(this.RelationName) == true)
            {
                return(null);
            }

            Type objectType = null;
            ICustomTypeDescriptor        customTypeDescriptor    = null;
            PropertyDescriptorCollection properties              = null;
            PropertyDescriptor           relationDescriptor      = null;
            TypeDescriptionProvider      typeDescriptionProvider = null;

            if (iTypedList != null)
            {
                properties = iTypedList.GetItemProperties(null);

                if ((properties != null) && (properties.Count > 0))
                {
                    relationDescriptor = properties[this.RelationName];
                }
                else
                {
                    string listName = iTypedList.GetListName(null);

                    if (string.IsNullOrEmpty(listName) == false)
                    {
                        objectType = Type.GetType(listName, false, false);

                        if (objectType != null)
                        {
                            typeDescriptionProvider = TypeDescriptor.GetProvider(objectType);
                            if (typeDescriptionProvider != null)
                            {
                                customTypeDescriptor = typeDescriptionProvider.GetTypeDescriptor(objectType);

                                if (customTypeDescriptor != null)
                                {
                                    properties = customTypeDescriptor.GetProperties();

                                    if ((properties != null) && (properties.Count > 0))
                                    {
                                        relationDescriptor = properties[this.RelationName];
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(relationDescriptor);
        }
Example #13
0
        /// <summary>
        /// 포커스가 가 있는 그리드의 정보를 데이터 테이블로 변환한다.
        /// </summary>
        /// <param name="pGrid">그리드.</param>
        /// <returns>리턴값</returns>
        public static DataTable GetPivotFocusedCellInfo(PivotGridControl pGrid, DataReturnType type)
        {
            try
            {
                DataTable table = new DataTable();

                if (type == DataReturnType.FocusedCell)
                {
                    PivotSummaryDataSource dataSource = pGrid.Cells.GetFocusedCellInfo().CreateSummaryDataSource() as PivotSummaryDataSource;
                    ITypedList             list       = dataSource as ITypedList;
                    foreach (PropertyDescriptor property in list.GetItemProperties(null))
                    {
                        table.Columns.Add(property.Name, property.PropertyType);
                    }

                    for (int rowIndex = 0; rowIndex < dataSource.RowCount; rowIndex++)
                    {
                        object[] values = new object[table.Columns.Count];
                        for (int columnIndex = 0; columnIndex < table.Columns.Count; columnIndex++)
                        {
                            values[columnIndex] = dataSource.GetValue(rowIndex, /*rowIndex*/ columnIndex);
                        }
                        table.Rows.Add(values);
                    }
                }
                else if (type == DataReturnType.All)
                {
                    PivotSummaryDataSource dataSourceAll = pGrid.CreateSummaryDataSource() as PivotSummaryDataSource;
                    ITypedList             listAll       = dataSourceAll as ITypedList;
                    foreach (PropertyDescriptor property in listAll.GetItemProperties(null))
                    {
                        table.Columns.Add(property.Name, property.PropertyType);
                    }
                    for (int rowIndex = 0; rowIndex < dataSourceAll.RowCount; rowIndex++)
                    {
                        object[] values = new object[table.Columns.Count];
                        for (int columnIndex = 0; columnIndex < table.Columns.Count; columnIndex++)
                        {
                            values[columnIndex] = dataSourceAll.GetValue(rowIndex, /*rowIndex*/ columnIndex);
                        }
                        table.Rows.Add(values);
                    }
                }


                return(table);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #14
0
        ///<inheritdoc/>
        public System.ComponentModel.PropertyDescriptorCollection GetItemProperties(System.ComponentModel.PropertyDescriptor[] listAccessors)
        {
            ITypedList tlist = list as ITypedList;

            if (tlist == null)
            {
                return(null);
            }
            else
            {
                return(tlist.GetItemProperties(listAccessors));
            }
        }
        /// <include file='doc\DesignTimeData.uex' path='docs/doc[@for="DesignTimeData.GetDataMember"]/*' />
        /// <devdoc>
        /// </devdoc>
        public static IEnumerable GetDataMember(IListSource dataSource, string dataMember)
        {
            IEnumerable list = null;

            IList memberList = dataSource.GetList();

            if ((memberList != null) && (memberList is ITypedList))
            {
                if (dataSource.ContainsListCollection == false)
                {
                    Debug.Assert((dataMember == null) || (dataMember.Length == 0), "List does not contain data members");
                    if ((dataMember != null) && (dataMember.Length != 0))
                    {
                        throw new ArgumentException();
                    }
                    list = (IEnumerable)memberList;
                }
                else
                {
                    ITypedList typedMemberList = (ITypedList)memberList;

                    PropertyDescriptorCollection propDescs = typedMemberList.GetItemProperties(new PropertyDescriptor[0]);
                    if ((propDescs != null) && (propDescs.Count != 0))
                    {
                        PropertyDescriptor listProperty = null;

                        if ((dataMember == null) || (dataMember.Length == 0))
                        {
                            listProperty = propDescs[0];
                        }
                        else
                        {
                            listProperty = propDescs.Find(dataMember, true);
                        }

                        if (listProperty != null)
                        {
                            object listRow    = memberList[0];
                            object listObject = listProperty.GetValue(listRow);

                            if ((listObject != null) && (listObject is IEnumerable))
                            {
                                list = (IEnumerable)listObject;
                            }
                        }
                    }
                }
            }

            return(list);
        }
Example #16
0
        private PropertyDescriptor GetPropertyDescriptorFromITypedList(ITypedList typedList)
        {
            if (string.IsNullOrEmpty(this.RelationName) || (typedList == null))
            {
                return(null);
            }

            PropertyDescriptorCollection properties;

            properties = typedList.GetItemProperties(null);
            if ((properties != null) && (properties.Count > 0))
            {
                return(properties[this.RelationName]);
            }

            var listName = typedList.GetListName(null);

            if (string.IsNullOrEmpty(listName))
            {
                return(null);
            }

            var itemType = Type.GetType(listName, false, false);

            if (itemType == null)
            {
                return(null);
            }

            var descriptionProvider = TypeDescriptor.GetProvider(itemType);

            if (descriptionProvider == null)
            {
                return(null);
            }

            var descriptor = descriptionProvider.GetTypeDescriptor(itemType);

            if (descriptor == null)
            {
                return(null);
            }

            properties = descriptor.GetProperties();
            if ((properties != null) && (properties.Count > 0))
            {
                return(properties[this.RelationName]);
            }

            return(null);
        }
Example #17
0
        private static PropertyDescriptorCollection GetListItemPropertiesByEnumerable(IEnumerable enumerable, PropertyDescriptor[] listAccessors)
        {
            if ((listAccessors == null) || (listAccessors.Length == 0))
            {
                return(GetListItemPropertiesByEnumerable(enumerable));
            }
            ITypedList list = enumerable as ITypedList;

            if (list != null)
            {
                return(list.GetItemProperties(listAccessors));
            }
            return(GetListItemPropertiesByEnumerable(enumerable, listAccessors, 0));
        }
        /// <summary>
        /// The following code was obtained by using Reflector(tm).
        /// It tries to transform any object into something IEnumerable
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="dataMember"></param>
        /// <returns></returns>
        internal static IEnumerable GetResolvedDataSource(object dataSource, string dataMember)
        {
            if (dataSource == null)
            {
                return(null);
            }
            IListSource source1 = dataSource as IListSource;

            if (source1 != null)
            {
                IList list1 = source1.GetList();
                if (!source1.ContainsListCollection)
                {
                    return(list1);
                }
                if ((list1 != null) && (list1 is ITypedList))
                {
                    ITypedList list2 = (ITypedList)list1;
                    PropertyDescriptorCollection collection1 = list2.GetItemProperties(new PropertyDescriptor[0]);
                    if ((collection1 == null) || (collection1.Count == 0))
                    {
                        throw new HttpException("ListSource_Without_DataMembers");
                    }
                    PropertyDescriptor descriptor1 = null;
                    if ((dataMember == null) || (dataMember.Length == 0))
                    {
                        descriptor1 = collection1[0];
                    }
                    else
                    {
                        descriptor1 = collection1.Find(dataMember, true);
                    }
                    if (descriptor1 != null)
                    {
                        object obj1 = list1[0];
                        object obj2 = descriptor1.GetValue(obj1);
                        if ((obj2 != null) && (obj2 is IEnumerable))
                        {
                            return((IEnumerable)obj2);
                        }
                    }
                    throw new HttpException("ListSource_Missing_DataMember");
                }
            }
            if (dataSource is IEnumerable)
            {
                return((IEnumerable)dataSource);
            }
            return(null);
        }
Example #19
0
 private IEnumerable GetResolvedDataSource()
 {
     if (this.DataSource == null)
     {
         return(null);
     }
     if (this.DataSource is IListSource)
     {
         IListSource iListSource = (IListSource)this.DataSource;
         IList       iList       = iListSource.GetList();
         if (!iListSource.ContainsListCollection)
         {
             return(iList);
         }
         if (iList != null && iList is ITypedList)
         {
             ITypedList iTypeList = ((ITypedList)iList);
             PropertyDescriptorCollection collection = iTypeList.GetItemProperties(new PropertyDescriptor[0]);
             if ((collection != null) && (collection.Count != 0))
             {
                 PropertyDescriptor discriptor = null;
                 if ((this.DataMember == null) || (this.DataMember.Length == 0))
                 {
                     discriptor = collection[0];
                 }
                 else
                 {
                     discriptor = collection.Find(this.DataMember, true);
                 }
                 if (discriptor != null)
                 {
                     object key = iList[0];
                     object val = discriptor.GetValue(key);
                     if ((val != null) && val is IEnumerable)
                     {
                         return((IEnumerable)val);
                     }
                 }
                 throw new HttpException("The datasource does not contain a member named " + this.DataMember);
             }
             throw new HttpException("Datasource does not contain any members.");
         }
     }
     if (this.DataSource is IEnumerable)
     {
         return((IEnumerable)this.DataSource);
     }
     return(null);
 }
Example #20
0
        public static int Find(this BindingSource source, params Key[] keys)
        {
            PropertyDescriptor[] properties = new PropertyDescriptor[keys.Length];

            ITypedList typedList = source as ITypedList;

            if (source.Count <= 0)
            {
                return(-1);
            }

            PropertyDescriptorCollection props;

            if (typedList != null) // obtain the PropertyDescriptors from the list
            {
                props = typedList.GetItemProperties(null);
            }
            else // use the TypeDescriptor on the first element of the list
            {
                props = TypeDescriptor.GetProperties(source[0]);
            }

            for (int i = 0; i < keys.Length; i++)
            {
                properties[i] = props.Find(keys[i].PropertyName, true); // will throw if the property isn't found
            }

            for (int i = 0; i < source.Count; i++)
            {
                object row   = source[i];
                bool   match = true;

                for (int p = 0; p < keys.Length; p++)
                {
                    if (properties[p].GetValue(row) != keys[p].Value)
                    {
                        match = false;
                        break;
                    }
                }

                if (match)
                {
                    return(i);
                }
            }

            return(-1);
        }
Example #21
0
        /// <summary>
        /// Transforms the given dictionary.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private DataTable Transform(ITypedList data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (!(data is IEnumerable))
            {
                throw new ArgumentException(string.Format("data is of type '{0}', not IEnumerable.", data.GetType()));
            }

            // define a table...
            DataTable table = this.CreateDataTable();

            // get the props...
            PropertyDescriptorCollection properties = data.GetItemProperties(new PropertyDescriptor[] {});

            if (properties == null)
            {
                throw new InvalidOperationException("properties is null.");
            }

            // create columns...
            foreach (PropertyDescriptor property in properties)
            {
                // create...
                DataColumn column = new DataColumn(property.Name, property.PropertyType);
                table.Columns.Add(column);
            }

            // do the rows...
            object[] values = new object[properties.Count];
            foreach (object obj in (IEnumerable)data)
            {
                // get the values...
                for (int index = 0; index < properties.Count; index++)
                {
                    // get a value...
                    object value = properties[index].GetValue(obj);
                    values[index] = value;
                }

                // add...
                table.Rows.Add(values);
            }

            // return...
            return(table);
        }
        public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            List <PropertyDescriptor> result = new List <PropertyDescriptor>();

            foreach (PropertyDescriptor pd in NestedTypedList.GetItemProperties(ExtractOriginalDescriptors(listAccessors)))
            {
                object nullVal = null;
                if (pd.PropertyType == typeof(string))
                {
                    nullVal = "[empty]";
                }
                result.Add(new EmptyObjectPropertyDescriptor(pd, NullObject, null));
            }
            return(new PropertyDescriptorCollection(result.ToArray()));
        }
        public static string[] GetColumnNames(ITypedList typedList)
        {
            var props      = typedList.GetItemProperties(null);
            var columnList = new List <string>(props.Count);

            for (var i = 0; i < props.Count; i++)
            {
                if (props[i].PropertyType == typeof(IBindingList))
                {
                    continue;
                }
                columnList.Add(props[i].Name);
            }
            return(columnList.ToArray());
        }
Example #24
0
 public static IEnumerable GetResolvedDataSource(object source, string member)
 {
     if (source != null && source is IListSource)
     {
         IListSource src  = (IListSource)source;
         IList       list = src.GetList();
         if (!src.ContainsListCollection)
         {
             return(list);
         }
         if (list != null && list is ITypedList)
         {
             ITypedList tlist = (ITypedList)list;
             PropertyDescriptorCollection pdc = tlist.GetItemProperties(new PropertyDescriptor[0]);
             if (pdc != null && pdc.Count > 0)
             {
                 PropertyDescriptor pd = null;
                 if (member != null && member.Length > 0)
                 {
                     pd = pdc.Find(member, true);
                 }
                 else
                 {
                     pd = pdc[0];
                 }
                 if (pd != null)
                 {
                     object rv = pd.GetValue(list[0]);
                     if (rv != null && rv is IEnumerable)
                     {
                         return((IEnumerable)rv);
                     }
                 }
                 throw new HttpException(
                           String.Format("Can't find specified DataMember [{0}] in the DataSource", member));
             }
             throw new HttpException("DataSource doesn't contain any DataMembers");
         }
     }
     if (source is IEnumerable)
     {
         return((IEnumerable)source);
     }
     return(null);
 }
Example #25
0
        private static PropertyDescriptorCollection GetListItemPropertiesByEnumerable(IEnumerable enumerable)
        {
            PropertyDescriptorCollection properties = null;

            System.Type c = enumerable.GetType();
            if (typeof(Array).IsAssignableFrom(c))
            {
                properties = TypeDescriptor.GetProperties(c.GetElementType(), BrowsableAttributeList);
            }
            else
            {
                ITypedList list = enumerable as ITypedList;
                if (list != null)
                {
                    properties = list.GetItemProperties(null);
                }
                else
                {
                    PropertyInfo typedIndexer = GetTypedIndexer(c);
                    if ((typedIndexer != null) && !typeof(ICustomTypeDescriptor).IsAssignableFrom(typedIndexer.PropertyType))
                    {
                        properties = TypeDescriptor.GetProperties(typedIndexer.PropertyType, BrowsableAttributeList);
                    }
                }
            }
            if (properties != null)
            {
                return(properties);
            }
            object firstItemByEnumerable = GetFirstItemByEnumerable(enumerable);

            if (!(enumerable is string))
            {
                if (firstItemByEnumerable == null)
                {
                    return(new PropertyDescriptorCollection(null));
                }
                properties = TypeDescriptor.GetProperties(firstItemByEnumerable, BrowsableAttributeList);
                if ((enumerable is IList) || ((properties != null) && (properties.Count != 0)))
                {
                    return(properties);
                }
            }
            return(TypeDescriptor.GetProperties(enumerable, BrowsableAttributeList));
        }
Example #26
0
        private static PropertyDescriptorCollection GetListItemPropertiesByEnumerable(IEnumerable enumerable, PropertyDescriptor[] listAccessors) {
            PropertyDescriptorCollection pdc = null;

            if ((null == listAccessors) || (listAccessors.Length == 0)) {
                pdc = GetListItemPropertiesByEnumerable(enumerable);
            }
            else  {
                ITypedList typedList = enumerable as ITypedList;
                if (typedList != null) {
                    pdc = typedList.GetItemProperties(listAccessors);
                }
                else {
                    // Walk the tree
                    pdc = GetListItemPropertiesByEnumerable(enumerable, listAccessors, 0);
                }
            }
            return pdc;
        }
Example #27
0
 // borrowed from Mono's System.Web implementation
 protected IEnumerable GetResolvedDataSource(object source, string member)
 {
     if (source != null && source is IListSource)
     {
         IListSource src  = (IListSource)source;
         IList       list = src.GetList();
         if (!src.ContainsListCollection)
         {
             return(list);
         }
         if (list != null && list is ITypedList)
         {
             ITypedList tlist = (ITypedList)list;
             PropertyDescriptorCollection pdc = tlist.GetItemProperties(new PropertyDescriptor[0]);
             if (pdc != null && pdc.Count > 0)
             {
                 PropertyDescriptor pd = null;
                 if (member != null && member.Length > 0)
                 {
                     pd = pdc.Find(member, true);
                 }
                 else
                 {
                     pd = pdc[0];
                 }
                 if (pd != null)
                 {
                     object rv = pd.GetValue(list[0]);
                     if (rv != null && rv is IEnumerable)
                     {
                         return((IEnumerable)rv);
                     }
                 }
                 throw new Exception("ListSource_Missing_DataMember");
             }
             throw new Exception("ListSource_Without_DataMembers");
         }
     }
     if (source is IEnumerable)
     {
         return((IEnumerable)source);
     }
     return(null);
 }
Example #28
0
        private static PropertyDescriptorCollection GetListItemPropertiesByEnumerable(IEnumerable enumerable) { 
            PropertyDescriptorCollection pdc = null;
            Type targetType = enumerable.GetType();

            if (typeof(Array).IsAssignableFrom(targetType)) { 
                pdc = TypeDescriptor.GetProperties(targetType.GetElementType(), BrowsableAttributeList);
            } 
            else { 
                ITypedList typedListEnumerable = enumerable as ITypedList;
                if (typedListEnumerable != null) { 
                    pdc = typedListEnumerable.GetItemProperties(null);
                }
                else {
                    PropertyInfo indexer = GetTypedIndexer(targetType); 

                    if (indexer != null && !typeof(ICustomTypeDescriptor).IsAssignableFrom(indexer.PropertyType)) { 
                        pdc = TypeDescriptor.GetProperties(indexer.PropertyType, BrowsableAttributeList); 
                    }
                } 
            }

            // See if we were successful - if not, return the shape of the first
            // item in the list 
            if (null == pdc) {
                object instance = GetFirstItemByEnumerable(enumerable); 
                if (enumerable is string) { 
                    pdc = TypeDescriptor.GetProperties(enumerable, BrowsableAttributeList);
                } 
                else if (instance == null) {
                    pdc = new PropertyDescriptorCollection(null);
                }
                else { 
                    pdc = TypeDescriptor.GetProperties(instance, BrowsableAttributeList);
 
                    if (!(enumerable is IList) && (pdc == null || pdc.Count == 0)) { 
                        pdc = TypeDescriptor.GetProperties(enumerable, BrowsableAttributeList);
                    } 
                }

            }
 
            // Return results
            return pdc; 
        } 
Example #29
0
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            ISelectionService selectionService = (ISelectionService)context.GetService(typeof(ISelectionService));
            object            dataSource       = TypeDescriptor.GetProperties(selectionService.PrimarySelection)["DataSource"].GetValue(selectionService.PrimarySelection);
            ITypedList        listSource       = (dataSource as ITypedList);

            if (listSource == null)
            {
                return(new StandardValuesCollection(null));
            }
            PropertyDescriptorCollection properties = listSource.GetItemProperties(null);

            string[] members = new string[properties.Count];
            for (int i = 0; i < properties.Count; i++)
            {
                members[i] = properties[i].Name;
            }
            return(new StandardValuesCollection(members));
        }
        private void EnumeratorGrid_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                if (EnumeratorGrid.SelectedRows.Count == 0)
                {
                    return;
                }

                string text = String.Empty;

                ITypedList list = EnumeratorGrid.DataSource as ITypedList;
                if (null != list)
                {
                    PropertyDescriptorCollection properties = list.GetItemProperties(null);
                    if (null != properties)
                    {
                        object item     = EnumeratorGrid.SelectedRows[0].DataBoundItem;
                        Type   itemType = item.GetType();

                        foreach (PropertyDescriptor descriptor in properties)
                        {
                            object value = itemType.InvokeMember(descriptor.Name,
                                                                 BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance, null, item, null);
                            if (null != value)
                            {
                                text += descriptor.Name + ":" + value.ToString() + Environment.NewLine;
                            }
                        }
                    }
                }

                if (text != String.Empty)
                {
                    ShowOverlayText(text);
                }
            }
            catch (Exception exception)
            {
                ShowOverlayError(exception);
            }
        }
    private PropertyDescriptor GetPropertyDescriptorFromITypedList( ITypedList typedList )
    {
      if( string.IsNullOrEmpty( this.RelationName ) || ( typedList == null ) )
        return null;

      PropertyDescriptorCollection properties;

      properties = typedList.GetItemProperties( null );
      if( ( properties != null ) && ( properties.Count > 0 ) )
        return properties[ this.RelationName ];

      var listName = typedList.GetListName( null );
      if( string.IsNullOrEmpty( listName ) )
        return null;

      var itemType = Type.GetType( listName, false, false );
      if( itemType == null )
        return null;

      var descriptionProvider = TypeDescriptor.GetProvider( itemType );
      if( descriptionProvider == null )
        return null;

      var descriptor = descriptionProvider.GetTypeDescriptor( itemType );
      if( descriptor == null )
        return null;

      properties = descriptor.GetProperties();
      if( ( properties != null ) && ( properties.Count > 0 ) )
        return properties[ this.RelationName ];

      return null;
    }
    private PropertyDescriptor GetPropertyDescriptorFromITypedList( ITypedList iTypedList )
    {
      if( string.IsNullOrEmpty( this.RelationName ) == true )
        return null;

      Type objectType = null;
      ICustomTypeDescriptor customTypeDescriptor = null;
      PropertyDescriptorCollection properties = null;
      PropertyDescriptor relationDescriptor = null;
      TypeDescriptionProvider typeDescriptionProvider = null;

      if( iTypedList != null )
      {
        properties = iTypedList.GetItemProperties( null );

        if( ( properties != null ) && ( properties.Count > 0 ) )
        {
          relationDescriptor = properties[ this.RelationName ];
        }
        else
        {
          string listName = iTypedList.GetListName( null );

          if( string.IsNullOrEmpty( listName ) == false )
          {
            objectType = Type.GetType( listName, false, false );

            if( objectType != null )
            {
              typeDescriptionProvider = TypeDescriptor.GetProvider( objectType );
              if( typeDescriptionProvider != null )
              {
                customTypeDescriptor = typeDescriptionProvider.GetTypeDescriptor( objectType );

                if( customTypeDescriptor != null )
                {
                  properties = customTypeDescriptor.GetProperties();

                  if( ( properties != null ) && ( properties.Count > 0 ) )
                    relationDescriptor = properties[ this.RelationName ];
                }
              }
            }
          }
        }
      }

      return relationDescriptor;
    }
 private static PropertyDescriptor GetDescriptor(ITypedList bindingListView, string propName)
 {
     var descriptorCollection = bindingListView.GetItemProperties(new PropertyDescriptor[0]);
     return descriptorCollection.Find(propName, true);
 }
 internal EntityDataSourceViewSchema(ITypedList typedList)
 {
     PropertyDescriptorCollection properties = typedList.GetItemProperties(null);
     CreateColumnsFromPropDescs(properties, null);
 }