PageRenderTime 21ms CodeModel.GetById 15ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/V4/PrismLibrary/Desktop/Prism.TestSupport/CollectionChangedTracker.cs

#
C# | 42 lines | 22 code | 4 blank | 16 comment | 0 complexity | 7f30b71446af3b0a45eef8830d0d61a1 MD5 | raw file
 1//===================================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
 4//===================================================================================
 5// Copyright (c) Microsoft Corporation.  All rights reserved.
 6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 9// FITNESS FOR A PARTICULAR PURPOSE.
10//===================================================================================
11// The example companies, organizations, products, domain names,
12// e-mail addresses, logos, people, places, and events depicted
13// herein are fictitious.  No association with any real company,
14// organization, product, domain name, email address, logo, person,
15// places, or events is intended or should be inferred.
16//===================================================================================
17using System;
18using System.Collections.Generic;
19using System.Collections.Specialized;
20using System.Linq;
21using System.Text;
22
23namespace Microsoft.Practices.Prism.TestSupport
24{
25    public class CollectionChangedTracker
26    {
27        private readonly List<NotifyCollectionChangedEventArgs> eventList = new List<NotifyCollectionChangedEventArgs>();
28
29        public CollectionChangedTracker(INotifyCollectionChanged collection)
30        {
31            collection.CollectionChanged += OnCollectionChanged;
32        }
33
34        public IEnumerable<NotifyCollectionChangedAction> ActionsFired { get { return this.eventList.Select(e => e.Action);  } }
35        public IEnumerable<NotifyCollectionChangedEventArgs> NotifyEvents { get { return this.eventList; } }
36        
37        private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
38        {
39            this.eventList.Add(e);
40        }
41    }
42}