Fix potential order inconsistency of element and property lists.
This commit is contained in:
20
Assets/Cryville/Common/Collections/Generic/PairCollection.cs
Normal file
20
Assets/Cryville/Common/Collections/Generic/PairCollection.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user