src/AppMotor.Core/Extensions/TypeExtensions.cs
/// <summary>
/// Returns the <see cref="MethodInfo"/> for the specified custom operator defined in this type.
/// For binary operators (i.e. with two parameters/operands), this method assumes that both operands
/// are of 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="unary">The operators "+" and "-" exist both as unary and binary operator.
/// If <c>true</c>, the unary operator is returned; if <c>false</c>, the binary operator
/// is returned.</param>
Returns the  for the specified custom operator defined in this type.
For binary operators , this method assumes that both operands
are of this type. Returns null
Returns the for the specified custom operator defined in this type . For binary operators this method assumes that both operands are of this type . Returns null
[MustUseReturnValue]
    public static MethodInfo? GetOperator(this Type type, string @operator, bool unary = false)
    {
        UnaryOperators? unaryOperator = @operator switch
        {
            "+"  => unary ? UnaryOperators.UnaryPlus : null,
            "-"  => unary ? UnaryOperators.UnaryNegation : null,
            "++" => UnaryOperators.Increment,
            "--" => UnaryOperators.Decrement,
            "!"  => UnaryOperators.LogicalNot,
            "~"  => UnaryOperators.OnesComplement,
            _    => null,
        };
        if (unaryOperator != null)
        {
            return type.GetOperator(unaryOperator.Value);
        }
        else
        {
            switch (@operator)
            {
                case "<<":
                    return type.GetOperator(BinaryOperators.LeftShift, otherType: typeof(int));
                case ">>":
                    return type.GetOperator(BinaryOperators.RightShift, otherType: typeof(int));
                default:
                    return type.GetOperator(@operator, otherType: type);
            }
        }
    }
[ MustUseReturnValue ] public static MethodInfo ? GetOperator ( this Type type , string @operator , bool unary = false ) { UnaryOperators ? unaryOperator = @operator switch { " " => unary ? UnaryOperators . UnaryPlus : null , " " => unary ? UnaryOperators . UnaryNegation : null , " " => UnaryOperators . Increment , " " => UnaryOperators . Decrement , " " => UnaryOperators . LogicalNot , " " => UnaryOperators . OnesComplement , _ => null , } ; if ( unaryOperator != null ) { return type . GetOperator ( unaryOperator . Value ) ; } else { switch ( @operator ) { case " " : return type . GetOperator ( BinaryOperators . LeftShift , otherType : typeof ( int ) ) ; case " " : return type . GetOperator ( BinaryOperators . RightShift , otherType : typeof ( int ) ) ; default : return type . GetOperator ( @operator , otherType : type ) ; } } }
Returns the  for the specified custom operator defined in this type.
Returns the for the specified custom operator defined in this type .
Type
this
@operator
string
unary
bool
The operators "+" and "-" exist both as unary and binary operator.
If truefalse
The operators " + " and " - " exist both as unary and binary operator . If truefalse
type
None
operator
The operator as string
The operator as string