2023-02-26 09:38:28 +00:00
|
|
|
namespace InnovEnergy.Lib.Units;
|
2023-02-25 14:53:58 +00:00
|
|
|
|
|
|
|
public readonly struct State
|
|
|
|
{
|
|
|
|
public IReadOnlyList<String> Values { get; }
|
|
|
|
|
2023-03-01 07:25:23 +00:00
|
|
|
public State(IReadOnlyList<String> values)
|
|
|
|
{
|
|
|
|
if (values.Any(v => v.Contains(";")))
|
|
|
|
throw new ArgumentException("State values cannot contain the character ;", nameof(values));
|
|
|
|
|
|
|
|
Values = values;
|
|
|
|
}
|
2023-02-25 14:53:58 +00:00
|
|
|
|
|
|
|
public State(params String[] values) : this((IReadOnlyList<String>)values){}
|
2023-03-01 09:38:46 +00:00
|
|
|
public State(params State[] states) : this((IReadOnlyList<String>)states.SelectMany(s => s.Values).ToList()){}
|
2023-02-25 14:53:58 +00:00
|
|
|
|
2023-03-01 07:29:36 +00:00
|
|
|
public static implicit operator State(String s) => new State(s);
|
|
|
|
public static implicit operator State(Enum e) => new State(e.ToString());
|
|
|
|
public static implicit operator State(Boolean s) => new State(s.ToString());
|
2023-03-01 09:38:46 +00:00
|
|
|
public static implicit operator State(List<String> s) => new State((IReadOnlyList<String>)s);
|
2023-02-25 14:53:58 +00:00
|
|
|
|
2023-03-01 07:05:57 +00:00
|
|
|
public static State operator |(State left, State right) => new State(left, right);
|
2023-03-01 07:25:23 +00:00
|
|
|
|
|
|
|
public override String ToString() => String.Join("; ", Values);
|
2023-02-25 14:53:58 +00:00
|
|
|
}
|