コード例 #1
0
        // Assumes index >= 0, returns null if index >= Count
        public object GetDataItem(int index)
        {
            Debug.Assert(index >= 0);

            IList list = this.List;

            if (list != null)
            {
                return((index < list.Count) ? list[index] : null);
            }

            PagedCollectionView collectionView = this.DataSource as PagedCollectionView;

            if (collectionView != null)
            {
                return((index < collectionView.Count) ? collectionView.GetItemAt(index) : null);
            }

            IEnumerable enumerable = this.DataSource;

            if (enumerable != null)
            {
                IEnumerator enumerator = enumerable.GetEnumerator();
                int         i          = -1;
                while (enumerator.MoveNext() && i < index)
                {
                    i++;
                    if (i == index)
                    {
                        return(enumerator.Current);
                    }
                }
            }
            return(null);
        }
コード例 #2
0
        // Assumes index >= 0, returns null if index >= Count
        public object GetDataItem(int index)
        {
            Debug.Assert(index >= 0, "Expected positive index.");

            IList list = this.List;

            if (list != null)
            {
                return((index < list.Count) ? list[index] : null);
            }

#if FEATURE_PAGEDCOLLECTIONVIEW
            PagedCollectionView collectionView = this.DataSource as PagedCollectionView;
            if (collectionView != null)
            {
                return((index < collectionView.Count) ? collectionView.GetItemAt(index) : null);
            }
#endif

            IEnumerable enumerable = this.DataSource;
            if (enumerable != null)
            {
                IEnumerator enumerator = enumerable.GetEnumerator();
                int         i          = -1;
                while (enumerator.MoveNext() && i < index)
                {
                    i++;
                    if (i == index)
                    {
                        return(enumerator.Current);
                    }
                }
            }

            return(null);
        }