Add more implicit conversions for State

This commit is contained in:
atef 2023-03-02 15:14:22 +01:00
parent 55048b3f99
commit a3ccd2a537
1 changed files with 8 additions and 5 deletions

View File

@ -15,12 +15,15 @@ public readonly struct State
public State(params String[] values) : this((IReadOnlyList<String>)values){}
public State(params State[] states) : this((IReadOnlyList<String>)states.SelectMany(s => s.Values).ToList()){}
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());
public static implicit operator State(List<String> s) => new State((IReadOnlyList<String>)s);
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<String> s) => new((IReadOnlyList<String>)s);
public static implicit operator State(String[] s) => new((IReadOnlyList<String>)s);
public static implicit operator State(List<Enum> es) => new(es.Select(e => e.ToString()).ToArray());
public static implicit operator State(Enum[] es) => new(es.Select(e => e.ToString()).ToArray());
public static State operator |(State left, State right) => new State(left, right);
public static State operator |(State left, State right) => new(left, right);
public override String ToString() => String.Join("; ", Values);
}