扩展System.Type的"<"和">"运算符

Joh*_*nes 0 c# operator-overloading

可能重复:
使用C#扩展方法重载运算符

我如何重载这些运算符,我觉得编译器误解了.

我认为核心问题是我试图将运算符重载为类的扩展.类型类没有那些运算符,所以我觉得这样做很安全 - 但我的编译器不同意.

    public static class TypeCheck
    {
        public static Boolean ToBool(this Type t1, Type t2)
        {
            //normal extension works
            return true;
        }

        public static Boolean operator > (this Type t1, Type t2)
        {
            //TODO once it compiles
            return fasle;
        }

        public static Boolean operator < (this Type t1, Type t2)
        {
            //TODO once it compiles
            return true;
        }

    }
Run Code Online (Sandbox Code Playgroud)

为了阐明这些比较的领域细节:class A : B {},class B {}class C {} A是比其余部分大于A和大于乙但较小.因为A.IsCastableTo(B)和A.IsCastableTo(A);

dtb*_*dtb 7

C#中没有"扩展操作符".

至少有一个操作符参数必须是声明操作符的类型.