mirror of
https://github.com/mm201/pkmn-classic-framework.git
synced 2026-04-24 23:36:51 -05:00
Added Indexer1d helper from gamefloor.
This commit is contained in:
parent
61bda8e871
commit
9e33f63ecb
|
|
@ -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" />
|
||||
|
|
|
|||
65
library/Support/Indexer1d.cs
Normal file
65
library/Support/Indexer1d.cs
Normal 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);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user