歧义扩展方法 [英] Ambiguous extension method

查看:81
本文介绍了歧义扩展方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对扩展方法进行以下调用:

I am making the following call to an extension method:

database.ExecuteScalar(command).NoNull<string>(string.Empty);

我得到一个错误,即扩展方法不明确。

I get an error that the extension method is ambiguous .

我有两个具有相同代码的dll,它们在不同的命名空间下实现 NoNull(string str)

I have two dlls with the same code that implement NoNull(string str) under different namespaces.

如何明确地引用一个名称空间?

How can I explicitly refer to one namespace?

如果它是相同的名称空间,我该怎么办?

How would I have it done if it was the same namespace?

更新:我无法重写第三方dll。

推荐答案


  1. 通过重新定义或消除源代码中的一种方法来消除歧义。您不需要冗余。

  2. 如果您不控制源,请通过使用指令。

  3. 如果在给定的类文件中仍然需要两个命名空间,则只需将其作为静态类调用来调用所需的版本,即可通过完全限定的类名明确标识该方法。 / li>
  1. Remove the ambiguity by redefining or eliminating one of the methods at the source. You don't need redundancy.
  2. If you do not control the source, include only one of them in your class file via the using directive.
  3. If you still need both namespaces in the given class file, invoke the version you wish simply as a static class call, unambiguously identifying the method via a fully qualified class name.

-

 Abc.Xyz.ExtensionsClass.NoNull(database.ExecuteScalar(), string.Empty);

这篇关于歧义扩展方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆