implement ToString for State
This commit is contained in:
parent
f6f4326afa
commit
08c747f2ea
|
@ -7,13 +7,7 @@ public readonly struct Percent
|
||||||
public static String Unit => "%";
|
public static String Unit => "%";
|
||||||
public static String Symbol => "%"; // ??
|
public static String Symbol => "%"; // ??
|
||||||
|
|
||||||
public Percent(Decimal value)
|
public Percent(Decimal value) => Value = value;
|
||||||
{
|
|
||||||
if (value < 0)
|
|
||||||
throw new ArgumentException(nameof(Frequency) + " cannot be negative", nameof(value));
|
|
||||||
|
|
||||||
Value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// not generated
|
// not generated
|
||||||
|
|
||||||
|
@ -21,9 +15,9 @@ public readonly struct Percent
|
||||||
public override String ToString() => Value + Unit;
|
public override String ToString() => Value + Unit;
|
||||||
|
|
||||||
// scalar multiplication
|
// scalar multiplication
|
||||||
public static Decimal operator *(Decimal scalar, T t) => scalar * t.Value/100m;
|
public static Decimal operator *(Decimal scalar, T t) => scalar * t.Value / 100m;
|
||||||
public static Decimal operator *(T t, Decimal scalar) => scalar * t.Value/100m;
|
public static Decimal operator *(T t, Decimal scalar) => scalar * t.Value / 100m;
|
||||||
|
|
||||||
// parallel
|
// parallel
|
||||||
public static Percent operator |(T left, T right) => new T((left.Value + right.Value)/2m);
|
public static Percent operator |(T left, T right) => new T((left.Value + right.Value) / 2m);
|
||||||
}
|
}
|
|
@ -4,7 +4,13 @@ public readonly struct State
|
||||||
{
|
{
|
||||||
public IReadOnlyList<String> Values { get; }
|
public IReadOnlyList<String> Values { get; }
|
||||||
|
|
||||||
public State(IReadOnlyList<String> values) => Values = values;
|
public State(IReadOnlyList<String> 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<String>)values){}
|
public State(params String[] values) : this((IReadOnlyList<String>)values){}
|
||||||
public State(params State[] states) : this(states.SelectMany(s => s.Values).ToList()){}
|
public State(params State[] states) : this(states.SelectMany(s => s.Values).ToList()){}
|
||||||
|
@ -15,4 +21,6 @@ public readonly struct State
|
||||||
public static implicit operator State(String s) => new State(s);
|
public static implicit operator State(String s) => new State(s);
|
||||||
|
|
||||||
public static State operator |(State left, State right) => new State(left, right);
|
public static State operator |(State left, State right) => new State(left, right);
|
||||||
|
|
||||||
|
public override String ToString() => String.Join("; ", Values);
|
||||||
}
|
}
|
Loading…
Reference in New Issue