Function request: Class contracts - default require and ensure for type aliases

Or just something like:

type
  KG = public record
  private
     fValue: Double;
   public
      constructor(aValue: Double); 
      begin 
        fValue := aValue; 
       {$IFDEF DEBUG}
       if aValue < 0 then raise new ArgumentException('Invalid value!');
       {$ENDIF}
     end;
     operator explicit(aValue: Double): KG; begin exit new KG(aValue) ;end;
     operator explicit(aValue: KG): Double; begin exit aValue.Value; ;end;
     property Value: Double read fValue;
     method ToString: String; override;
     begin
       exit fValue.ToString()+' kg';
     end;
  end;

Yes, but compare the resulting IL in release mode between that record and type kg = double;
I only want checks, no performance penalty.

On .NET this should be pretty much fully inlined in release mode(admittedly I didn’t profile it)

Never mind, I am going to build it myself using an Aspect.

Another option is a mapped type.

namespace ConsoleApplication833;

type
  KG = public record mapped to Double
   public
      constructor(aValue: Double); inline;
      begin 
        self := aValue; 
       {$IFDEF DEBUG}
       if aValue < 0 then raise new ArgumentException('Invalid value!');
       {$ENDIF}
     end;
     property Value: Double read mapped;
    class operator Implicit(aVal: Double): KG; inline;
    begin 
      exit new KG(aVal);
    end;
     method ToString: String; override;
     begin
       exit mapped.ToString()+' kg';
     end;
  end;
  Program = class
  public

    class method Main(args: array of String): Int32;
    begin
      var x: KG := KG(15.0);
      x := Double(x) + 15;
      // add your own code here
      writeLn('The magic happens here.');
    end;

  end;

end.

becomes:

// ConsoleApplication833.Program
using System;

public static int Main(string[] args)
{
	double num = default(double);
	num = 15.0;
	if (15.0 < 0.0)
	{
		throw new ArgumentException("Invalid value!");
	}
	double x2 = num;
	x2 += 15.0;
	Console.Out.WriteLine("The magic happens here.");
	int Result = default(int);
	return Result;
}