using System; using System.Collections; using System.Collections.Generic; namespace Cryville.Common.Collections.Generic { public struct PairCollection : IDisposable { public void Dispose() { } readonly IPairList _pairList; readonly IDictionary _dictionary; public PairCollection(object collection) : this() { var type = collection.GetType(); if (typeof(IPairList).IsAssignableFrom(type)) _pairList = (IPairList)collection; else if (typeof(IDictionary).IsAssignableFrom(type)) _dictionary = (IDictionary)collection; else throw new ArgumentException("Parameter is not a pair collection"); } public void Add(object key, object value) { if (_pairList != null) _pairList.Add(key, value); else _dictionary.Add(key, value); } } public struct PairCollection : IDisposable { public void Dispose() { } readonly IPairList _pairList; readonly IDictionary _dictionary; public PairCollection(object collection) : this() { var type = collection.GetType(); if (typeof(IPairList).IsAssignableFrom(type)) _pairList = (IPairList)collection; else if (typeof(IDictionary).IsAssignableFrom(type)) _dictionary = (IDictionary)collection; else throw new ArgumentException("Parameter is not a pair collection"); } public void Add(TKey key, TValue value) { if (_pairList != null) _pairList.Add(key, value); else _dictionary.Add(key, value); } } }