This is a mirror of official site: http://jasper-net.blogspot.com/

ObservableDictionary (C#)

| Monday, December 27, 2010
Few weeks ago I posted an ObservableDictionary(Of TKey, TValue) in VB.NET, today I had some time to translate it to C# (not tested, just translated, kindly notice me for any error).

using System;
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections.Specialized;

namespace System.Collections.ObjectModel
{
 class ObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue>, INotifyCollectionChanged, INotifyPropertyChanged
 {
   private const string CountString = "Count";
   private const string IndexerName = "Item[]";
   private IDictionary<TKey, TValue> _Dictionary;
   protected IDictionary<TKey, TValue> Dictionary
   {
     get { return _Dictionary; }
   }

   #region Constructors
   public ObservableDictionary()
   {
     _Dictionary = new Dictionary<TKey, TValue>();
   }
   public ObservableDictionary(IDictionary<TKey, TValue> dictionary)
   {
     _Dictionary = new Dictionary<TKey, TValue>(dictionary);
   }
   public ObservableDictionary(IEqualityComparer<TKey> comparer)
   {
     _Dictionary = new Dictionary<TKey, TValue>(comparer);
   }
   public ObservableDictionary(int capacity)
   {
     _Dictionary = new Dictionary<TKey, TValue>(capacity);
   }
   public ObservableDictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer)
   {
     _Dictionary = new Dictionary<TKey, TValue>(dictionary, comparer);
   }
   public ObservableDictionary(int capacity, IEqualityComparer<TKey> comparer)
   {
     _Dictionary = new Dictionary<TKey, TValue>(capacity, comparer);
   }
   

Posted via email from .NET Info

0 comments: