【问题标题】:Ambiguous call using extension methods in asp.net在 asp.net 中使用扩展方法的模糊调用
【发布时间】:2013-04-03 00:52:30
【问题描述】:

从另一个扩展方法调用扩展方法时,我的解决方案构建正常,但在已发布的站点(或虚拟 asp.net 服务器)中,我收到编译错误“歧义调用”。

public static string ExtensionMethodA(this ObjectToExtend myObj){//code here}

public static string ExtensionMethodB(this ObjectToExtend myObj){
   string a = myObj.ExtensionMethodA(); // this line causes the error.
   return a;
}

【问题讨论】:

    标签: asp.net extension-methods


    【解决方案1】:

    我没有阅读足够的内容来确切地知道原因,但这里是解决方案:

    public static string ExtensionMethodA(this ObjectToExtend myObj){//code here}
    
    public static string ExtensionMethodB(this ObjectToExtend myObj){
        string a = ExtensionMethodA(myObj); // correct call.
        return a;
     }
    

    【讨论】:

    • 最好的办法是编辑您的问题并询问为什么这种行为是这样的。从您的问答看来,您是在显式调用一种方法而不是另一种方法,那么为什么传递对象会有所不同?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-22
    相关资源
    最近更新 更多