using System.Collections; namespace InnovEnergy.Lib.Units; public readonly struct State : IReadOnlyList { public IReadOnlyList Values { get; } public State(IReadOnlyList values) { if (values.Any(v => v.Contains(";"))) throw new ArgumentException("State values cannot contain the character ;", nameof(values)); Values = values; } public State(params String[] values) : this((IReadOnlyList)values){} public State(params State[] states) : this((IReadOnlyList)states.SelectMany(s => s.Values).ToList()){} public static implicit operator State(String s) => new(s); public static implicit operator State(Enum e) => new(e.ToString()); public static implicit operator State(Boolean s) => new(s.ToString()); public static implicit operator State(List s) => new((IReadOnlyList)s); public static implicit operator State(String[] s) => new((IReadOnlyList)s); public static implicit operator State(List es) => new(es.Select(e => e.ToString()).ToList()); public static implicit operator State(Enum[] es) => new(es.Select(e => e.ToString()).ToList()); public static State operator |(State left, State right) => new(left, right); public IEnumerator GetEnumerator() => Values.GetEnumerator(); public override String ToString() => String.Join("; ", Values); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); public Int32 Count => Values.Count; public String this[Int32 index] => Values[index]; public static State From(T t) where T : Enum { return new State(t); } }