This sample demonstrates C# operator overloads and value-object behavior using a
small Money domain type.
Money.cs— a readonly record struct with arithmetic operators,withexpressions,BigIntegercents, and currency checks.Currency.cs— currency enum used by the value object.NoSameMoneyCurrencyException.cs— domain exception emitted as a TypeScript error class.CurrencyExceptions.cs— exceptions deriving from BCL exceptions: .NET-style message composition (ArgumentExceptionparameter suffix), aMessageoverride two levels below the BCL base, and: this(...)chained constructors forwarding the inner exception ascause.PriceRule.cs— constructor and method overloads with default values (an enum and adecimaldefault) andparamsarrays, dispatched at runtime.Tagged.cs— a generic class whose constructor overloads mix a type-parameter-typed parameter with a concrete one of the same arity.Program.cs— top-level code that creates money, applies+=, and writes the result.
This sample is useful for inspecting generated static operator helpers,
exception lowering, BigInteger mapping, record-struct output, and arithmetic
expressions.
The related TypeScript source is in targets/js/sample-operator-overloading/src:
money.tscurrency.tsno-same-money-currency-exception.tsinvalid-currency-code-exception.ts,unsupported-currency-exception.ts,currency-conversion-exception.tsprice-rule.ts,tagged.tsprogram.tsindex.ts
The target package lives in targets/js/sample-operator-overloading.
dotnet build samples/SampleOperatorOverloading/SampleOperatorOverloading.csproj
cd targets/js/sample-operator-overloading
bun install
bun run build