Vogen
Vogen copied to clipboard
Clone underlying operators
Describe the feature
Clone the operators on the underlying type. For instance:
ValueObject[typeof(int)]`
public partial struct Age {
}
Age a1 = Age.From(20);
Age a2 = Age.From(30);
(a1 < a2).Should().BeTrue();
(a1 + a2).Should().Be(50);
(a1 / 2).Should().Be(10);
... etc.
We want to take the known operators from the know primitive runtime types. The known types are:
- byte
- sbyte
- short
- ushort
- int
- uint
- long
- ulong
- nint
- nuint
- float
- double
- char,
- bool
The known operators are (from here:
| C++ operator symbol | Name of alternative method | Name of operator |
|---|---|---|
| Not defined | ToXxx or FromXxx | op_Implicit |
| Not defined | ToXxx or FromXxx | op_Explicit |
| + (binary) | Add | op_Addition |
| - (binary) | Subtract | op_Subtraction |
| * (binary) | Multiply | op_Multiply |
| / | Divide | op_Division |
| % | Mod | op_Modulus |
| ^ | Xor | op_ExclusiveOr |
| & (binary) | BitwiseAnd | op_BitwiseAnd |
| | | BitwiseOr | op_BitwiseOr |
| && | And | op_LogicalAnd |
| || | Or | op_LogicalOr |
| = | Assign | op_Assign |
| << | LeftShift | op_LeftShift |
| >> | RightShift | op_RightShift |
| Not defined | LeftShift | op_SignedRightShift |
| Not defined | RightShift | op_UnsignedRightShift |
| == | Equals | op_Equality |
| > | Compare | op_GreaterThan |
| < | Compare | op_LessThan |
| != | Compare | op_Inequality |
| >= | Compare | op_GreaterThanOrEqual |
| <= | Compare | op_LessThanOrEqual |
| *= | Multiply | op_MultiplicationAssignment |
| -= | Subtract | op_SubtractionAssignment |
| ^= | Xor | op_ExclusiveOrAssignment |
| <<= | LeftShift | op_LeftShiftAssignment |
| %= | Mod | op_ModulusAssignment |
| += | Add | op_AdditionAssignment |
| &= | BitwiseAnd | op_BitwiseAndAssignment |
| |= | BitwiseOr | op_BitwiseOrAssignment |
| , | None assigned | op_Comma |
| /= | Divide | op_DivisionAssignment |
| -- | Decrement | op_Decrement |
| ++ | Increment | op_Increment |
| - (unary) | Negate | op_UnaryNegation |
| + (unary) | Plus | op_UnaryPlus |
| ~ | OnesComplement | op_OnesComplement |
They're not declared for int as they're generated as part of the IL