Units which take advantage of C# 10 abstract interface members
namespace Mu.Units
interface IAddable where T : IAddable { static abstract operator+(IAddable left, IAddable right); }
interface ISubtractable where T : ISubtractable { static abstract operator-(IAddable left, IAddable right); }
interface IMultiplicatable where T: { static abstract operator*(IAddable left, IAddable right); }
interface IDivisible
interface IScalar : IAddable, ISubtractable, IMultiplicatable, IDivisible where T: IScalar { static abstract IScalar Zero; static abstract From(T value); static abstract To(T value); }
// Classes and structs (including built-ins) can implement interface struct Int32 : …, IScalar { static Int32 I.operator +(Int32 x, Int32 y) => x + y; // Explicit static Int32 I.operator -(Int32 x, Int32 y) => x - y; // Explicit public static int Zero => 0; // Implicit }
struct Double: _, IScalar { static Double I.operator +(Int32 x, Int32 y) => x + y; // Explicit public static int Zero => 0; // Implicit }
struct Distance : IScalar struct Duration : IScalar struct Force : IScalar
interface ICompoundScalar<T, TOver, TUnder> where TOver : IScalar where TUnder : IScalar { }
class Unit<IScalar>