Innovenergy_trunk/csharp/lib/Utils/None.cs

36 lines
1.4 KiB
C#
Raw Normal View History

2023-02-16 12:57:06 +00:00
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;
}