Added Indexer1d helper from gamefloor.

This commit is contained in:
Greg Edwards 2015-02-09 10:59:02 -05:00
parent 61bda8e871
commit 9e33f63ecb
2 changed files with 66 additions and 0 deletions

View File

@ -95,6 +95,7 @@
<Compile Include="Support\AssertHelper.cs" />
<Compile Include="Support\EncodedString4.cs" />
<Compile Include="Support\EncodedString5.cs" />
<Compile Include="Support\Indexer1d.cs" />
<Compile Include="Support\LazyKeyValuePair.cs" />
<Compile Include="Support\LocalizedString.cs" />
<Compile Include="Support\LogHelper.cs" />

View File

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace PkmnFoundations.Support
{
/// <summary>
/// Helper class to aid with the implementation of non-default indexers
/// </summary>
/// <typeparam name="T"></typeparam>
public class Indexer1d<TKey, TValue> : IReadOnlyIndexer1d<TKey, TValue>, IWriteOnlyIndexer1d<TKey, TValue>
{
public Indexer1d(Getter1d<TKey, TValue> getter, Setter1d<TKey, TValue> setter)
{
m_getter = getter;
m_setter = setter;
}
private Getter1d<TKey, TValue> m_getter;
private Setter1d<TKey, TValue> m_setter;
public TValue this[TKey index]
{
get
{
return m_getter(index);
}
set
{
m_setter(index, value);
}
}
}
public class ReadOnlyIndexer1d<TKey, TValue> : IReadOnlyIndexer1d<TKey, TValue>
{
public ReadOnlyIndexer1d(Getter1d<TKey, TValue> getter)
{
m_getter = getter;
}
private Getter1d<TKey, TValue> m_getter;
public TValue this[TKey index]
{
get
{
return m_getter(index);
}
}
}
public interface IReadOnlyIndexer1d<in TKey, out TValue>
{
TValue this[TKey index] { get; }
}
public interface IWriteOnlyIndexer1d<in TKey, in TValue>
{
TValue this[TKey index] { set; }
}
public delegate TValue Getter1d<TKey, TValue>(TKey index);
public delegate void Setter1d<TKey, TValue>(TKey index, TValue value);
}