/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Framework / MS / Internal / Data / DifferencingCollection.cs / 1 / DifferencingCollection.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// Description: ObservableCollection that updates by differencing against
// an IEnumerable
//
//---------------------------------------------------------------------------
/***************************************************************************\
This class maps an IEnumerable into an ObservableCollection. The idea is
to initialize the collection with the items in the enumerable. When the
user of the class has reason to believe the enumerable has changed, he
should call Update. This re-enumerates the enumerable and brings the
collection up to sync, and also raises appropriate collection-change
notifications. A differencing algorithm detects simple changes, such
as adding/removing a single item, moving a single item, or replacing an
item, and raises the corresponding Add, Remove, Move or Replace event.
All other changes result in a Reset event.
The constructor and the Update method have an IEnumerable parameter. It's not
required that these be the same - you can Update against a different IEnumerable
than the constructor used. This makes sense if they enumerate the same
items (up to simple changes).
This class is used to support XLinq's Elements and Descendants properties, both
of which return IEnumerables that don't raise collection-change events. XLinq
returns different IEnumerables every time you fetch the property value, so the
flexibility of the previous paragraph comes into play.
\***************************************************************************/
using System;
using System.Collections; // IEnumerable
using System.Collections.Generic; // IList
using System.Collections.ObjectModel; // ObservableCollection
using System.Collections.Specialized; // INotifyCollectionChanged
using System.ComponentModel; // PropertyChangedEventArgs
using MS.Internal; // Invariant.Assert
namespace MS.Internal.Data
{
internal sealed class DifferencingCollection : ObservableCollection