src/AppMotor.Core/Extensions/TypeExtensions.cs
/// <summary>
/// Returns the <see cref="MethodInfo"/> for the specified custom binary (i.e. two parameters/operands) operator
/// defined in this type. Returns <c>null</c>, if the operator method doesn't exist.
/// </summary>
/// <param name="type"></param>
/// <param name="operator">The operator as string (e.g. "+", "/", "==", ...)</param>
/// <param name="otherType">The type of the other operand (one is always this type);
/// can be the same as this type</param>
/// <param name="otherTypeIsSecondOperand">Whether <paramref name="otherType"/> is used as first (<c>false</c>)
/// or as second (<c>true</c>) operand; the latter is the default</param>
Returns the  for the specified custom binary  operator
defined in this type. Returns null
Returns the for the specified custom binary operator defined in this type . Returns null
[MustUseReturnValue]
    public static MethodInfo? GetOperator(this Type type, string @operator, Type otherType, bool otherTypeIsSecondOperand = true)
    {
        BinaryOperators binaryOperator = @operator switch
        {
            "+"  => BinaryOperators.Addition,
            "-"  => BinaryOperators.Subtraction,
            "*"  => BinaryOperators.Multiply,
            "/"  => BinaryOperators.Division,
            "%"  => BinaryOperators.Modulus,
            "==" => BinaryOperators.Equality,
            "!=" => BinaryOperators.Inequality,
            "<"  => BinaryOperators.LessThan,
            ">"  => BinaryOperators.GreaterThan,
            "<=" => BinaryOperators.LessThanOrEqual,
            ">=" => BinaryOperators.GreaterThanOrEqual,
            "&"  => BinaryOperators.BitwiseAnd,
            "|"  => BinaryOperators.BitwiseOr,
            "^"  => BinaryOperators.ExclusiveOr,
            "<<" => BinaryOperators.LeftShift,
            ">>" => BinaryOperators.RightShift,
            _    => throw new ArgumentException($"The operator '{@operator}' is not a valid binary operator."),
        };
        return type.GetOperator(binaryOperator, otherType, otherTypeIsSecondOperand);
    }
[ MustUseReturnValue ] public static MethodInfo ? GetOperator ( this Type type , string @operator , Type otherType , bool otherTypeIsSecondOperand = true ) { BinaryOperators binaryOperator = @operator switch { " " => BinaryOperators . Addition , " " => BinaryOperators . Subtraction , " " => BinaryOperators . Multiply , " " => BinaryOperators . Division , " " => BinaryOperators . Modulus , " " => BinaryOperators . Equality , " " => BinaryOperators . Inequality , " " => BinaryOperators . LessThan , " " => BinaryOperators . GreaterThan , " " => BinaryOperators . LessThanOrEqual , " " => BinaryOperators . GreaterThanOrEqual , " " => BinaryOperators . BitwiseAnd , " " => BinaryOperators . BitwiseOr , " " => BinaryOperators . ExclusiveOr , " " => BinaryOperators . LeftShift , " " => BinaryOperators . RightShift , _ => throw new ArgumentException ( $" The operator ' { @operator } ' is not a valid binary operator. " ) , } ; return type . GetOperator ( binaryOperator , otherType , otherTypeIsSecondOperand ) ; }
Returns the  for the specified custom binary (i.e.
Returns the for the specified custom binary ( i . e .
Type
this
@operator
string
otherType
Type
The type of the other operand (one is always this type);
can be the same as this type
The type of the other operand ( one is always this type ) ; can be the same as this type
otherTypeIsSecondOperand
bool
Whether  is used as first (falsetrue
Whether is used as first ( falsetrue
type
None
operator
The operator as string
The operator as string