21 lines
709 B
C#
21 lines
709 B
C#
using System;
|
|
using System.Collections;
|
|
|
|
namespace Cryville.Common.Collections.Generic {
|
|
public struct PairCollection : IDisposable {
|
|
public void Dispose() { }
|
|
IPairList _pairList;
|
|
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);
|
|
}
|
|
}
|
|
}
|