enhance Cache to allow specializing the key comparer

This commit is contained in:
Chris Forbes
2011-03-06 08:56:39 +13:00
parent 516efa1dc8
commit 8d1a69e8ff

View File

@@ -15,17 +15,21 @@ using System.Collections.Generic;
namespace OpenRA.FileFormats
{
public class Cache<T, U> : IEnumerable<KeyValuePair<T, U>>
{
Dictionary<T, U> hax = new Dictionary<T, U>();
{
Dictionary<T, U> hax;
Func<T,U> loader;
public Cache(Func<T,U> loader)
public Cache(Func<T,U> loader, IEqualityComparer<T> c)
{
hax = new Dictionary<T, U>(c);
if (loader == null)
throw new ArgumentNullException();
this.loader = loader;
}
}
public Cache(Func<T, U> loader)
: this(loader, EqualityComparer<T>.Default) { }
public U this[T key]
{