Innovenergy_trunk/csharp/Lib/Utils/None.cs

37 lines
1.4 KiB
C#

using System.Diagnostics.Contracts;
namespace InnovEnergy.Lib.Utils;
// taken from https://github.com/louthy/language-ext/blob/main/LanguageExt.Core/DataTypes/Unit/Unit.cs
/// <summary>
/// A unit type is a type that allows only one value (and thus can hold no information)
/// </summary>
[Serializable]
public readonly struct None : IEquatable<None>, IComparable<None>
{
// ReSharper disable once InconsistentNaming
public static readonly None none = new None();
[Pure] public override Int32 GetHashCode() => 0;
[Pure] public override Boolean Equals(Object? obj) => obj is None;
[Pure] public override String ToString() => "<none>";
[Pure] public Boolean Equals(None other) => true;
[Pure] public static Boolean operator ==(None lhs, None rhs) => true;
[Pure] public static Boolean operator !=(None lhs, None rhs) => false;
[Pure] public static Boolean operator > (None lhs, None rhs) => false;
[Pure] public static Boolean operator >=(None lhs, None rhs) => true;
[Pure] public static Boolean operator < (None lhs, None rhs) => false;
[Pure] public static Boolean operator <=(None lhs, None rhs) => true;
[Pure] public Int32 CompareTo(None other) => 0;
[Pure] public static None operator +(None a, None b) => none;
[Pure] public static implicit operator ValueTuple(None _) => default;
[Pure] public static implicit operator None(ValueTuple _) => default;
}