6 public abstract class Either<T, U> where T : notnull where U : notnull
11 public static explicit operator T(
Either<T, U> e) => e.TryGet(out T t) ? t :
throw new InvalidCastException($
"Contained object is not of type {typeof(T).Name}");
12 public static explicit operator U(
Either<T, U> e) => e.TryGet(out U u) ? u :
throw new InvalidCastException($
"Contained object is not of type {typeof(U).Name}");
14 public abstract bool TryGet(out T t);
15 public abstract bool TryGet(out U u);
21 public abstract override bool Equals(
object? obj);
26 => a is
null ? b is null : a.Equals(b);
32 public sealed
class EitherT<T, U> :
Either<T, U> where T : notnull where U : notnull
39 => $
"Either<{typeof(T).NameWithGenerics()}, {typeof(U).NameWithGenerics()}>({Value}: {typeof(T).NameWithGenerics()})";
41 public override bool TryGet(out T t) { t =
Value;
return true; }
42 public override bool TryGet(out U u) { u =
default!;
return false; }
46 if (
Value is V result)
58 public override bool Equals(
object? obj)
62 T value =>
Value.Equals(value),
69 public sealed
class EitherU<T, U> :
Either<T, U> where T : notnull where U : notnull
76 => $
"Either<{typeof(T).NameWithGenerics()}, {typeof(U).NameWithGenerics()}>({Value}: {typeof(U).NameWithGenerics()})";
78 public override bool TryGet(out T t) { t =
default!;
return false; }
79 public override bool TryGet(out U u) { u =
Value;
return true; }
83 if (
Value is V result)
95 public override bool Equals(
object? obj)
99 U value =>
Value.Equals(value),
abstract override int GetHashCode()
abstract bool TryCast< V >(out V v)
abstract override bool Equals(object? obj)
abstract override? string ToString()
static bool operator==(Either< T, U >? a, Either< T, U >? b)
abstract bool TryGet(out U u)
abstract bool TryGet(out T t)
static bool operator!=(Either< T, U >? a, Either< T, U >? b)
override? string ToString()
override bool TryGet(out T t)
override int GetHashCode()
override bool Equals(object? obj)
override bool TryCast< V >(out V v)
override bool TryGet(out U u)
override int GetHashCode()
override bool TryCast< V >(out V v)
override bool TryGet(out T t)
override? string ToString()
override bool TryGet(out U u)
override bool Equals(object? obj)