protected internal override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
        {
            EntityObject entityObject = parentItem as EntityObject;

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

            // Even if EntityObject is not in a loadable state, we must still return the IList
            // so that the ItemProperties can be extracted based on the elements type.
            bool entityObjectLoadable = ItemsSourceHelper.IsEntityObjectLoadable(entityObject);

            // We let the user take charge of handling the details.
            QueryEntityDetailsEventArgs args = new QueryEntityDetailsEventArgs(entityObject);

            if (entityObjectLoadable)
            {
                this.OnQueryDetails(args);
            }

            // The parentItem must implement IEntityWithRelationships
            Type parentItemType = parentItem.GetType();

            if (typeof(IEntityWithRelationships).IsAssignableFrom(parentItemType))
            {
                // Since the relationship was based on the the property
                // name, we must find that property using reflection.
                PropertyInfo propertyInfo = parentItemType.GetProperty(this.RelationName);

                if (propertyInfo != null)
                {
                    RelatedEnd relatedEnd = propertyInfo.GetValue(parentItem, null) as RelatedEnd;

                    if (relatedEnd != null)
                    {
                        // Make sure that the details are loaded
                        // except if the user already handled it.
                        if (!relatedEnd.IsLoaded &&
                            !args.Handled &&
                            entityObjectLoadable)
                        {
                            relatedEnd.Load();
                        }

                        IListSource listSource = relatedEnd as IListSource;

                        // Returns an IList to have proper change notification events.
                        if (listSource != null)
                        {
                            return(listSource.GetList());
                        }
                    }
                }
            }

            return(null);
        }
コード例 #2
0
        public void WriteData(AMFWriter writer, object data)
        {
            IList list = data as IList;

            if (list != null)
            {
                writer.WriteByte(AMF3TypeCode.Array);
                writer.WriteAMF3Array(list);
                return;
            }

            IListSource listSource = data as IListSource;

            if (listSource != null)
            {
                writer.WriteByte(AMF3TypeCode.Array);
                writer.WriteAMF3Array(listSource.GetList());
                return;
            }

            IDictionary dictionary = data as IDictionary;

            if (dictionary != null)
            {
                writer.WriteByte(AMF3TypeCode.Dictionary);
                writer.WriteAMF3Dictionary(dictionary);
                return;
            }
            if (data is Exception)
            {
                writer.WriteByte(AMF3TypeCode.Object);
                writer.WriteAMF3Object(data);
                return;
            }
            if (data is IExternalizable)
            {
                writer.WriteByte(AMF3TypeCode.Object);
                writer.WriteAMF3Object(data);
                return;
            }
            if (data is IEnumerable)
            {
                ArrayList tmp = new ArrayList();
                foreach (object element in (data as IEnumerable))
                {
                    tmp.Add(element);
                }

                writer.WriteByte(AMF3TypeCode.Array);
                writer.WriteAMF3Array(tmp);

                return;
            }
            writer.WriteByte(AMF3TypeCode.Object);
            writer.WriteAMF3Object(data);
        }
コード例 #3
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);
        }
コード例 #4
0
        // Token: 0x060074ED RID: 29933 RVA: 0x002173BC File Offset: 0x002155BC
        public object Convert(object o, Type type, object parameter, CultureInfo culture)
        {
            IList       result     = null;
            IListSource listSource = o as IListSource;

            if (listSource != null)
            {
                result = listSource.GetList();
            }
            return(result);
        }
コード例 #5
0
    public static object Wrap(object obj)
    {
        IListSource ls = obj as IListSource;

        if (ls != null)
        {
            obj = ls.GetList();                 // list expansions
        }
        IList list = obj as IList;

        return(list == null ? obj : new ListWrapper(list));
    }
コード例 #6
0
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------


        //------------------------------------------------------
        //
        //  Interfaces (IValueConverter)
        //
        //------------------------------------------------------

        public object Convert(object o, Type type, object parameter, CultureInfo culture)
        {
            IList       il  = null;
            IListSource ils = o as IListSource;

            if (ils != null)
            {
                il = ils.GetList();
            }

            return(il);
        }
コード例 #7
0
 public static IBindingListView ListSourceToBindingListView(IListSource listSource)
 {
     if (listSource != null)
     {
         var list = listSource.GetList();
         if (list != null)
         {
             return(list.ToBindingListView());
         }
     }
     return(null);
 }
コード例 #8
0
        public IEnumerable <string> Toplist(bool ascendingByRating = true)
        {
            var movies = listSource.GetList();

            if (movies is null)
            {
                return new List <string>()
                       {
                           "Could not retrieve movies from source"
                       }
            }
            ;
            if (ascendingByRating)
            {
                return(movies.OrderBy(movie => double.Parse(movie.rated)).ToList().Select(movie => movie.title));
            }
            else
            {
                return(movies.OrderByDescending(movie => double.Parse(movie.rated)).ToList().Select(movie => movie.title));
            }
        }
コード例 #9
0
        /// <summary>
        /// Gets the resolved data source.
        /// </summary>
        /// <param name="dataSource">Data source.</param>
        /// <param name="dataMember">Data member.</param>
        /// <returns>Resolved data source enumerator.</returns>
        public static IEnumerable GetResolvedDataSource(object dataSource, string dataMember)
        {
            if (dataSource == null)
            {
                return(null);
            }
            IListSource iListSource = dataSource as IListSource;

            if (iListSource != null)
            {
                IList iList = iListSource.GetList();
                if (!iListSource.ContainsListCollection)
                {
                    return(iList);
                }
                if (iList != null && iList is ITypedList)
                {
                    PropertyDescriptorCollection propertyDescriptorCollection = ((ITypedList)iList).GetItemProperties(new PropertyDescriptor[0]);
                    if (propertyDescriptorCollection == null || propertyDescriptorCollection.Count == 0)
                    {
                        throw new HttpException("List source without DataMembers");
                    }
                    PropertyDescriptor propertyDescriptor = null;
                    if (dataMember == null || dataMember.Length == 0)
                    {
                        propertyDescriptor = propertyDescriptorCollection[0];
                    }
                    else
                    {
                        propertyDescriptor = propertyDescriptorCollection.Find(dataMember, true);
                    }
                    if (propertyDescriptor != null)
                    {
                        object local1 = iList[0];
                        object local2 = propertyDescriptor.GetValue(local1);
                        if (local2 != null && local2 is IEnumerable)
                        {
                            return((IEnumerable)local2);
                        }
                    }
                    throw new HttpException("List source missing DataMember");
                }
            }
            if (dataSource is IEnumerable)
            {
                return((IEnumerable)dataSource);
            }
            else
            {
                return(null);
            }
        }
コード例 #10
0
        protected internal override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
        {
            IListSource listSource = parentItem as IListSource;

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

            this.Seal();

            return(listSource.GetList());
        }
コード例 #11
0
        /// <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);
        }
コード例 #12
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);
        }
コード例 #13
0
        private IEnumerable <TItemType> GetListSourceData(IListSource listSource)
        {
            if (typeof(TItemType) != typeof(object))
            {
                throw new InvalidOperationException("Binding to an IListSource (such as DataSet or DataTable) requires that 'ItemType' be set to 'object'.");
            }

            var list = listSource.GetList();

            if (list == null)
            {
                throw new InvalidOperationException("The list returned by the IListSource (such as DataSet or DataTable) cannot be null.");
            }

            if (!listSource.ContainsListCollection)
            {
                // If this is the actual list, get it, and return it
                return(list.OfType <object>() as IEnumerable <TItemType>);
            }
            else
            {
                // If not, then this is a list of lists, so find the list within

                if (list is ITypedList typedList)
                {
                    var propDescs = typedList.GetItemProperties(Array.Empty <PropertyDescriptor>());
                    if (propDescs == null || propDescs.Count == 0)
                    {
                        throw new InvalidOperationException("The list returned by the IListSource (such as DataSet or DataTable) has no members. For example, the DataSet might have no DataTables in it.");
                    }

                    var listProperty = propDescs[0];
                    if (listProperty != null)
                    {
                        var listRow   = list[0];
                        var innerList = listProperty.GetValue(listRow);

                        if ((innerList != null) && (innerList is IEnumerable innerListEnumerable))
                        {
                            return(innerListEnumerable.OfType <object>() as IEnumerable <TItemType>);
                        }
                    }

                    throw new InvalidOperationException("The list returned by the IListSource (such as DataSet or DataTable) has no members. For example, the DataSet might have no DataTables in it.");
                }

                return(null);
            }
        }
コード例 #14
0
ファイル: ComboBox.cs プロジェクト: hkmujj/vin_zone_2009
 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);
 }
コード例 #15
0
 internal static IEnumerable GetResolvedDataSource(object dataSource, string dataMember)
 {
     if (dataSource != null)
     {
         IListSource source = dataSource as IListSource;
         if (source != null)
         {
             IList list = source.GetList();
             if (!source.ContainsListCollection)
             {
                 return(list);
             }
             if ((list != null) && (list is ITypedList))
             {
                 PropertyDescriptorCollection itemProperties = ((ITypedList)list).GetItemProperties(new PropertyDescriptor[0]);
                 if ((itemProperties == null) || (itemProperties.Count == 0))
                 {
                     throw new HttpException(System.Web.SR.GetString("ListSource_Without_DataMembers"));
                 }
                 PropertyDescriptor descriptor = null;
                 if (string.IsNullOrEmpty(dataMember))
                 {
                     descriptor = itemProperties[0];
                 }
                 else
                 {
                     descriptor = itemProperties.Find(dataMember, true);
                 }
                 if (descriptor != null)
                 {
                     object component = list[0];
                     object obj3      = descriptor.GetValue(component);
                     if ((obj3 != null) && (obj3 is IEnumerable))
                     {
                         return((IEnumerable)obj3);
                     }
                 }
                 throw new HttpException(System.Web.SR.GetString("ListSource_Missing_DataMember", new object[] { dataMember }));
             }
         }
         if (dataSource is IEnumerable)
         {
             return((IEnumerable)dataSource);
         }
     }
     return(null);
 }
コード例 #16
0
        /// <summary>
        ///     Returns binding list for the given query instance.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <returns></returns>
        public static IBindingList ToBindingList <T>(this IQueryable <T> source)
        {
            Validation.CheckArgumentNotNull(source, "source");
            IListSource listSource = source as IListSource;

            if (null == listSource)
            {
                throw new ArgumentException(Messages.UnableToGetBindingList, "source");
            }
            IBindingList bindingList = listSource.GetList() as IBindingList;

            if (null == bindingList)
            {
                throw new ArgumentException(Messages.UnableToGetBindingList, "source");
            }
            return(bindingList);
        }
コード例 #17
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);
 }
コード例 #18
0
    protected override void SetProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, object value)
    {
        ModelMetadata propertyMetadata = bindingContext.PropertyMetadata[propertyDescriptor.Name];

        propertyMetadata.Model = value;
        string modelStateKey = CreateSubPropertyName(bindingContext.ModelName, propertyMetadata.PropertyName);

        // Try to set a value into the property unless we know it will fail (read-only
        // properties and null values with non-nullable types)
        if (!propertyDescriptor.IsReadOnly)
        {
            try {
                if (value == null)
                {
                    propertyDescriptor.SetValue(bindingContext.Model, value);
                }
                else
                {
                    Type valueType = value.GetType();

                    if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(EntityCollection <>))
                    {
                        IListSource ls   = (IListSource)propertyDescriptor.GetValue(bindingContext.Model);
                        IList       list = ls.GetList();

                        foreach (var item in (IEnumerable)value)
                        {
                            list.Add(item);
                        }
                    }
                    else
                    {
                        propertyDescriptor.SetValue(bindingContext.Model, value);
                    }
                }
            }
            catch (Exception ex) {
                // Only add if we're not already invalid
                if (bindingContext.ModelState.IsValidField(modelStateKey))
                {
                    bindingContext.ModelState.AddModelError(modelStateKey, ex);
                }
            }
        }
    }
コード例 #19
0
        internal static object GetCurrentItem(object dataObject)
        {
            IListSource source = dataObject as IListSource;

            if (source != null)
            {
                dataObject = source.GetList();
            }

            if ((dataObject is IEnumerable) && !(dataObject is string))
            {
                return(CollectionViewSource.GetDefaultView(dataObject).CurrentItem);
            }
            else
            {
                return(dataObject);
            }
        }
コード例 #20
0
ファイル: DataGrid.cs プロジェクト: pmq20/mono_forked
 // 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);
 }
コード例 #21
0
ファイル: PowerDataGrid2.cs プロジェクト: radtek/datacenter
        /// <summary>
        /// 重写 <see cref="GridView"/>.OnDataBinding 事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDataBinding(EventArgs e)
        {
            IListSource listSource = this.DataSource as IListSource;

            if (listSource != null)
            {
                base.RecordCount = listSource.GetList().Count;
            }
            else
            {
                ICollection collection = this.DataSource as ICollection;
                if (collection != null)
                {
                    base.RecordCount = collection.Count;
                }
            }

            base.OnDataBinding(e);
        }
コード例 #22
0
        public void WriteData(AMFWriter writer, object data)
        {
            if (data is IList)
            {
                IList    list  = data as IList;
                object[] array = new object[list.Count];
                list.CopyTo(array, 0);
                writer.WriteArray(ObjectEncoding.AMF0, array);
                return;
            }
#if !(SILVERLIGHT)
            IListSource listSource = data as IListSource;
            if (listSource != null)
            {
                IList    list  = listSource.GetList();
                object[] array = new object[list.Count];
                list.CopyTo(array, 0);
                writer.WriteArray(ObjectEncoding.AMF0, array);
                return;
            }
#endif
            if (data is IDictionary)
            {
                writer.WriteAssociativeArray(ObjectEncoding.AMF0, data as IDictionary);
                return;
            }
            if (data is Exception)
            {
                writer.WriteASO(ObjectEncoding.AMF0, new ExceptionASO(data as Exception));
                return;
            }
            if (data is IEnumerable)
            {
                List <object> tmp = new List <object>();
                foreach (object element in (data as IEnumerable))
                {
                    tmp.Add(element);
                }
                writer.WriteArray(ObjectEncoding.AMF0, tmp.ToArray());
                return;
            }
            writer.WriteObject(ObjectEncoding.AMF0, data);
        }
コード例 #23
0
ファイル: TextComboBox.cs プロジェクト: sillsdev/WorldPad
        protected void DrawDataBoundMember(Graphics g, Brush brush, int index, Point point)
        {
            string text = string.Empty;

            if (DataSource != null)
            {
                IList list = null;
                // We coud be bound to an array list which implement the IList interface
                // or we could be bound to a DataSet which implements the IListSource from which
                // we can get the IList interface
                if (DataSource is IList)
                {
                    // Assume this is an array object and try to get the data based
                    // on this assumption
                    list = (IList)DataSource;
                    Debug.Assert(list != null, "ComboBox is bound to unrecognized DataSource");
                    // Now extract the actual text to be displayed
                    object o          = list[index];
                    Type   objectType = o.GetType();
                    // Now invoke the method that is associate with the
                    // Display name property of the ComboBox
                    PropertyInfo pi = objectType.GetProperty(DisplayMember);
                    text = (string)pi.GetValue(o, null);
                }
                else
                {
                    // Data set object
                    if (DataSource is IListSource)
                    {
                        IListSource ls = (IListSource)DataSource;
                        list = ls.GetList();
                        Debug.Assert(list != null, "ComboBox is bound to unrecognized DataSource");
                        // This is a data set object, get the value under that assumption
                        DataRowView dataRowView = (DataRowView)list[index];
                        DataRow     dataRow     = dataRowView.Row;
                        object      o           = dataRow[DisplayMember];
                        text = o.ToString();
                    }
                }
                g.DrawString(text, Font, brush, point);
            }
        }
コード例 #24
0
        public static IEnumerable GetDataMember(IListSource dataSource, string dataMember)
        {
            IEnumerable enumerable = null;
            IList       list       = dataSource.GetList();

            if ((list != null) && (list is ITypedList))
            {
                if (!dataSource.ContainsListCollection)
                {
                    if ((dataMember != null) && (dataMember.Length != 0))
                    {
                        throw new ArgumentException(System.Design.SR.GetString("DesignTimeData_BadDataMember"));
                    }
                    return(list);
                }
                PropertyDescriptorCollection itemProperties = ((ITypedList)list).GetItemProperties(new PropertyDescriptor[0]);
                if ((itemProperties == null) || (itemProperties.Count == 0))
                {
                    return(enumerable);
                }
                PropertyDescriptor descriptor = null;
                if ((dataMember == null) || (dataMember.Length == 0))
                {
                    descriptor = itemProperties[0];
                }
                else
                {
                    descriptor = itemProperties.Find(dataMember, true);
                }
                if (descriptor != null)
                {
                    object component = list[0];
                    object obj3      = descriptor.GetValue(component);
                    if ((obj3 != null) && (obj3 is IEnumerable))
                    {
                        enumerable = (IEnumerable)obj3;
                    }
                }
            }
            return(enumerable);
        }
コード例 #25
0
        public static IEnumerable GetSelectedDataSource(IComponent component, string dataSource, string dataMember)
        {
            IEnumerable enumerable         = null;
            object      selectedDataSource = GetSelectedDataSource(component, dataSource);

            if (selectedDataSource == null)
            {
                return(enumerable);
            }
            IListSource source = selectedDataSource as IListSource;

            if (source != null)
            {
                if (!source.ContainsListCollection)
                {
                    return(source.GetList());
                }
                return(GetDataMember(source, dataMember));
            }
            return((IEnumerable)selectedDataSource);
        }
コード例 #26
0
ファイル: Form1.cs プロジェクト: jeasonyoung/csharp_sfit
 static void WriteData(ref TextBox text, IListSource sources)
 {
     text.Text = "正在加载数据....";
     if (sources != null)
     {
         System.Collections.IList list = sources.GetList();
         if (list != null && list.Count > 0)
         {
             StringBuilder sb = new StringBuilder();
             for (int i = 0; i < list.Count; i++)
             {
                 object obj = list[i];
                 if (obj != null)
                 {
                     sb.AppendLine(string.Format("{0}.{1}", i + 1, obj));
                 }
             }
             text.Text = sb.ToString();
         }
     }
 }
コード例 #27
0
 public static IEnumerable GetDataMember(IListSource dataSource, string dataMember)
 {
     IEnumerable enumerable = null;
     IList list = dataSource.GetList();
     if ((list != null) && (list is ITypedList))
     {
         if (!dataSource.ContainsListCollection)
         {
             if ((dataMember != null) && (dataMember.Length != 0))
             {
                 throw new ArgumentException(System.Design.SR.GetString("DesignTimeData_BadDataMember"));
             }
             return list;
         }
         PropertyDescriptorCollection itemProperties = ((ITypedList) list).GetItemProperties(new PropertyDescriptor[0]);
         if ((itemProperties == null) || (itemProperties.Count == 0))
         {
             return enumerable;
         }
         PropertyDescriptor descriptor = null;
         if ((dataMember == null) || (dataMember.Length == 0))
         {
             descriptor = itemProperties[0];
         }
         else
         {
             descriptor = itemProperties.Find(dataMember, true);
         }
         if (descriptor != null)
         {
             object component = list[0];
             object obj3 = descriptor.GetValue(component);
             if ((obj3 != null) && (obj3 is IEnumerable))
             {
                 enumerable = (IEnumerable) obj3;
             }
         }
     }
     return enumerable;
 }
コード例 #28
0
ファイル: ObjectAdapter.cs プロジェクト: vivsrane/TestReports
        private List <string> GetColumns(object source)
        {
            List <string> result;
            // first handle DataSet/DataTable
            object      innerSource;
            IListSource iListSource = source as IListSource;

            if (iListSource != null)
            {
                innerSource = iListSource.GetList();
            }
            else
            {
                innerSource = source;
            }

            DataView dataView = innerSource as DataView;

            if (dataView != null)
            {
                result = ScanDataView(dataView);
            }
            else
            {
                // now handle lists/arrays/collections
                IEnumerable iEnumerable = innerSource as IEnumerable;
                if (iEnumerable != null)
                {
                    Type childType = Utilities.GetChildItemType(
                        innerSource.GetType());
                    result = ScanObject(childType);
                }
                else
                {
                    // the source is a regular object
                    result = ScanObject(innerSource.GetType());
                }
            }
            return(result);
        }
コード例 #29
0
 public static IEnumerable ToIEnumerable(Object dataSource)
 {
     if (dataSource == null)
     {
         return(null);
     }
     if (dataSource is IListSource)
     {
         IListSource source = (IListSource)dataSource;
         IList       list   = source.GetList();
         if (!source.ContainsListCollection)
         {
             return(list);
         }
         if ((list != null) && (list is ITypedList))
         {
             PropertyDescriptorCollection itemProperties = ((ITypedList)list).GetItemProperties(new PropertyDescriptor[0]);
             if ((itemProperties == null) || (itemProperties.Count == 0))
             {
                 return(null);
             }
             PropertyDescriptor descriptor = itemProperties[0];
             if (descriptor != null)
             {
                 Object component = list[0];
                 Object value     = descriptor.GetValue(component);
                 if ((value != null) && (value is IEnumerable))
                 {
                     return((IEnumerable)value);
                 }
             }
             return(null);
         }
     }
     if (dataSource is IEnumerable)
     {
         return((IEnumerable)dataSource);
     }
     return(null);
 }
コード例 #30
0
        private List <string> GetColumns(object source)
        {
            List <string> result;

            object      innerSource;
            IListSource iListSource = source as IListSource;

            if (iListSource != null)
            {
                innerSource = iListSource.GetList();
            }
            else
            {
                innerSource = source;
            }

            DataView dataView = innerSource as DataView;

            if (dataView != null)
            {
                result = ScanDataView(dataView);
            }
            else
            {
                IEnumerable iEnumerable = innerSource as IEnumerable;
                if (iEnumerable != null)
                {
                    Type childType = Utilities.GetChildItemType(
                        innerSource.GetType());
                    result = ScanObject(childType);
                }
                else
                {
                    result = ScanObject(innerSource.GetType());
                }
            }
            return(result);
        }
コード例 #31
0
ファイル: DataSourceHelper.cs プロジェクト: dox0/DotNet471RS3
        internal static IEnumerable GetResolvedDataSource(Object dataSource, String dataMember)
        {
            if (dataSource == null)
            {
                return(null);
            }

            IListSource listSource = dataSource as IListSource;

            if (listSource != null)
            {
                IList memberList = listSource.GetList();

                if (listSource.ContainsListCollection == false)
                {
                    // The returned list is itself the list we need to bind to.
                    // (Ignore DataMember parameter.)
                    return((IEnumerable)memberList);
                }

                if ((memberList != null) && (memberList is ITypedList))
                {
                    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 list    = listProperty.GetValue(listRow);

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

                        throw new ArgumentException(
                                  SR.GetString(SR.DataSourceHelper_MissingDataMember,
                                               dataMember));
                    }
                    else
                    {
                        throw new ArgumentException(
                                  SR.GetString(SR.DataSourceHelper_DataSourceWithoutDataMember,
                                               "List DataSource"));
                    }
                }
            }

            if (dataSource is IEnumerable)
            {
                return((IEnumerable)dataSource);
            }

            return(null);
        }
コード例 #32
0
 public IEnumerator GetEnumerator()
 {
     return(Target.GetList().GetEnumerator());
 }
コード例 #33
0
ファイル: Vector.cs プロジェクト: pirzada/sinapse
 public Vector(IListSource values)
     : this(values.GetList())
 {
 }