//------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="list">Underlying IList</param>
        public ListCollectionView(IList list)
            : base(list)
        {
            if (AllowsCrossThreadChanges)
            {
                BindingOperations.AccessCollection(list,
                    () =>
                    {
                        ClearPendingChanges();
                        ShadowCollection = new ArrayList((ICollection)SourceCollection);
                        _internalList = ShadowCollection;
                    },
                    false);
            }
            else
            {
                _internalList = list;
            }

            if (InternalList.Count == 0)    // don't call virtual IsEmpty in ctor
            {
                SetCurrent(null, -1, 0);
            }
            else
            {
                SetCurrent(InternalList[0], 0, 1);
            }

            _group = new CollectionViewGroupRoot(this);
            _group.GroupDescriptionChanged += new EventHandler(OnGroupDescriptionChanged);
            ((INotifyCollectionChanged)_group).CollectionChanged += new NotifyCollectionChangedEventHandler(OnGroupChanged);
            ((INotifyCollectionChanged)_group.GroupDescriptions).CollectionChanged += new NotifyCollectionChangedEventHandler(OnGroupByChanged);
        }
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="list">Underlying IBindingList</param>
        public BindingListCollectionView(IBindingList list)
            : base(list)
        {
            InternalList = list;
            _blv = list as IBindingListView;
            _isDataView = SystemDataHelper.IsDataView(list);

            SubscribeToChanges();

            _group = new CollectionViewGroupRoot(this);
            _group.GroupDescriptionChanged += new EventHandler(OnGroupDescriptionChanged);
            ((INotifyCollectionChanged)_group).CollectionChanged += new NotifyCollectionChangedEventHandler(OnGroupChanged);
            ((INotifyCollectionChanged)_group.GroupDescriptions).CollectionChanged += new NotifyCollectionChangedEventHandler(OnGroupByChanged);
        }
        //-----------------------------------------------------
        // 
        //  Constructors
        // 
        //----------------------------------------------------- 

        #region Constructors 

        /// <summary>
        /// Constructor
        /// </summary> 
        /// <param name="list">Underlying IList</param>
        public ListCollectionView(IList list) 
            : base(list) 
        {
            _internalList = list; 

            if (InternalList.Count == 0)    // don't call virtual IsEmpty in ctor
            {
                SetCurrent(null, -1, 0); 
            }
            else 
            { 
                SetCurrent(InternalList[0], 0, 1);
            } 

            _group = new CollectionViewGroupRoot(this);
            _group.GroupDescriptionChanged += new EventHandler(OnGroupDescriptionChanged);
            ((INotifyCollectionChanged)_group).CollectionChanged += new NotifyCollectionChangedEventHandler(OnGroupChanged); 
            ((INotifyCollectionChanged)_group.GroupDescriptions).CollectionChanged += new NotifyCollectionChangedEventHandler(OnGroupByChanged);
        } 
 public PagedCollectionView(IEnumerable source, bool isDataSorted, bool isDataInGroupOrder)
 {
     NotifyCollectionChangedEventHandler handler = null;
     this._cachedPageIndex = -1;
     this._currentChangedMonitor = new SimpleMonitor();
     this._flags = CollectionViewFlags.ShouldProcessCollectionChanged;
     this._pageIndex = -1;
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     this._sourceCollection = source;
     this.SetFlag(CollectionViewFlags.IsDataSorted, isDataSorted);
     this.SetFlag(CollectionViewFlags.IsDataInGroupOrder, isDataInGroupOrder);
     this._temporaryGroup = new CollectionViewGroupRoot(this, isDataInGroupOrder);
     this._group = new CollectionViewGroupRoot(this, false);
     this._group.GroupDescriptionChanged += new EventHandler(this.OnGroupDescriptionChanged);
     this._group.GroupDescriptions.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnGroupByChanged);
     this.CopySourceToInternalList();
     this._trackingEnumerator = source.GetEnumerator();
     if (this._internalList.Count > 0)
     {
         this.SetCurrent(this._internalList[0], 0, 1);
     }
     else
     {
         this.SetCurrent(null, -1, 0);
     }
     this.SetFlag(CollectionViewFlags.CachedIsEmpty, this.Count == 0);
     this._pollForChanges = !(source is INotifyCollectionChanged);
     if (!this._pollForChanges)
     {
         if (handler == null)
         {
             handler = delegate (object sender, NotifyCollectionChangedEventArgs args) {
                 this.ProcessCollectionChanged(args);
             };
         }
         (source as INotifyCollectionChanged).CollectionChanged += handler;
     }
 }
 private void PrepareTemporaryGroups()
 {
     this._temporaryGroup = new CollectionViewGroupRoot(this, this.CheckFlag(CollectionViewFlags.IsDataInGroupOrder));
     foreach (GroupDescription description in this._group.GroupDescriptions)
     {
         this._temporaryGroup.GroupDescriptions.Add(description);
     }
     this._temporaryGroup.Initialize();
     this._isGrouping = false;
     if (this._temporaryGroup.GroupDescriptions.Count > 0)
     {
         int num = 0;
         int count = this._internalList.Count;
         while (num < count)
         {
             object objB = this._internalList[num];
             if ((objB != null) && (!this.IsAddingNew || !object.Equals(this.CurrentAddItem, objB)))
             {
                 this._temporaryGroup.AddToSubgroups(objB, true);
             }
             num++;
         }
         if (this.IsAddingNew)
         {
             this._temporaryGroup.InsertSpecialItem(this._temporaryGroup.Items.Count, this.CurrentAddItem, true);
         }
     }
     this._isGrouping = this._temporaryGroup.GroupBy != null;
     this.PrepareGroupingComparer(this._temporaryGroup);
 }
 private void PrepareGroupingComparer(CollectionViewGroupRoot groupRoot)
 {
     if ((groupRoot == this._temporaryGroup) || (this.PageSize == 0))
     {
         CollectionViewGroupInternal.ListComparer activeComparer = groupRoot.ActiveComparer as CollectionViewGroupInternal.ListComparer;
         if (activeComparer != null)
         {
             activeComparer.ResetList(this.InternalList);
         }
         else
         {
             groupRoot.ActiveComparer = new CollectionViewGroupInternal.ListComparer(this.InternalList);
         }
     }
     else if (groupRoot == this._group)
     {
         groupRoot.ActiveComparer = new CollectionViewGroupInternal.CollectionViewGroupComparer(this._temporaryGroup);
     }
 }
 /// <summary>
 /// Sets our group to a new instance of a
 /// CollectionViewGroupRoot being passed in
 /// and resets the index.
 /// </summary>
 /// <param name="group">CollectionViewGroupRoot used to compare on</param>
 internal void ResetGroup(CollectionViewGroupRoot group)
 {
     this._group = group;
     this._index = 0;
 }
 /// <summary>
 /// Constructor for the CollectionViewGroupComparer that takes
 /// in an CollectionViewGroupRoot.
 /// </summary>
 /// <param name="group">CollectionViewGroupRoot used to compare on</param>
 internal CollectionViewGroupComparer(CollectionViewGroupRoot group)
 {
     this.ResetGroup(group);
 }
    /// <summary>
    /// Create a new instance of this class.
    /// </summary>
    /// <param name="query">The query providing the results to the collection</param>
    /// <param name="pageSize">The number of items to be displayed per page</param>
    /// <param name="loadSize">The number of items to be loaded when a page is requested</param>
    /// <param name="deferLoad">Whether to defer load</param>
    /// <param name="addPrimaryKeySort">Whether the data should be sorted on primary key</param>
    /// <remarks>
    /// Specify the <paramref name="query"/> which will be executed asynchronously to provide
    /// paged results.  If the first page should not be immediately loaded set <paramref name="deferLoad"/>
    /// to true, and call <see cref="Refresh()"/> when ready to retrieve data.
    /// </remarks>
    public EntityQueryPagedCollectionView(EntityQuery query, int pageSize, int loadSize, bool deferLoad, bool addPrimaryKeySort) {
      SortDescriptions = new SortDescriptionCollection();
      GroupDescriptions = new ObservableCollection<GroupDescription>();

      if (AnonymousFns.IsAnonymousType(query.ElementType)) {
        throw new NotSupportedException("Anonymous types are not currently supported.  To work around this limitation, you can instead project into a custom type.");
      }

      _groupRoot = new CollectionViewGroupRoot(GroupDescriptions);

      _baseQuery = query;
      _entityManager = query.EntityManager;
      if (_entityManager == null) throw new InvalidOperationException("The supplied query must have an assigned EntityManager.");
      _pageSize = pageSize < 0 ? 20 : pageSize;
      _lookAhead = GetLookAheadCount(_pageSize, loadSize);
      _sortByPrimaryKey = addPrimaryKeySort;
      _culture = CultureInfo.CurrentCulture;
      _innerList = (IList)TypeFns.ConstructGenericInstance(typeof(List<>), query.ElementType);

      InitFields();

      if (deferLoad) {
        _deferredLoadPending = true;
      } else {
        DoInitialLoad();
      }
    }
 internal void ResetGroup(CollectionViewGroupRoot group)
 {
     this._group = group;
     this._index = 0;
 }
 // Methods
 internal CollectionViewGroupComparer(CollectionViewGroupRoot group)
 {
     this.ResetGroup(group);
 }