Introduce State<T> for Enums
This commit is contained in:
parent
a66d547291
commit
9d753a8471
|
@ -34,4 +34,11 @@ public readonly struct State : IReadOnlyList<String>
|
||||||
|
|
||||||
public Int32 Count => Values.Count;
|
public Int32 Count => Values.Count;
|
||||||
public String this[Int32 index] => Values[index];
|
public String this[Int32 index] => Values[index];
|
||||||
}
|
|
||||||
|
public static State<T> From<T>(T t) where T : Enum
|
||||||
|
{
|
||||||
|
return new State<T>(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace InnovEnergy.Lib.Units;
|
||||||
|
|
||||||
|
public readonly struct State<T> : IReadOnlyList<T> where T:Enum
|
||||||
|
{
|
||||||
|
public IReadOnlyList<T> Values { get; }
|
||||||
|
|
||||||
|
public State(IReadOnlyList<T> values) => Values = values;
|
||||||
|
|
||||||
|
public State(params T[] values) : this((IReadOnlyList<T>)values){}
|
||||||
|
public State(params State<T>[] states) : this((IReadOnlyList<T>)states.SelectMany(s => s.Values).ToList()){}
|
||||||
|
|
||||||
|
public static implicit operator State<T>(T s) => new((IReadOnlyList<T>)s);
|
||||||
|
public static implicit operator State<T>(List<T> s) => new((IReadOnlyList<T>)s);
|
||||||
|
public static implicit operator State<T>(T[] s) => new((IReadOnlyList<T>)s);
|
||||||
|
|
||||||
|
public static State<T> operator |(State<T> left, State<T> right) => new State<T>(left, right);
|
||||||
|
|
||||||
|
public IEnumerator<T> GetEnumerator() => Values.GetEnumerator();
|
||||||
|
|
||||||
|
public override String ToString() => String.Join("; ", Values);
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
|
|
||||||
|
public Int32 Count => Values.Count;
|
||||||
|
public T this[Int32 index] => Values[index];
|
||||||
|
}
|
Loading…
Reference in New Issue