解决扩展方法/LINQ 歧义 [英] Resolving extension methods/LINQ ambiguity

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

问题描述

我正在为 ReSharper 4 编写插件.为此,我需要参考 ReSharper 的几个程序集.其中一个程序集 (JetBrains.Platform.ReSharper.Util.dll) 包含一个 System.Linq 命名空间,其中包含 System.Core 已提供的扩展方法的子集.

I'm writing an add-in for ReSharper 4. For this, I needed to reference several of ReSharper's assemblies. One of the assemblies (JetBrains.Platform.ReSharper.Util.dll) contains a System.Linq namespace, with a subset of extension methods already provided by System.Core.

当我编辑代码时,它会在这些扩展之间产生歧义,例如,我无法使用 OrderBy.我怎么能解决这个问题?我想使用核心 LINQ 扩展,而不是来自 ReSharper 的扩展.

When I edit the code, it creates an ambiguity between those extensions, so that I cannot use OrderBy, for instance. How could I solve this? I would like to use the core LINQ extensions, and not the ones from ReSharper.

尝试编译时出现以下错误:

I get the following error when trying to compile:

调用之间存在歧义以下方法或属性:'System.Linq.Enumerable.OrderBy(System.Collections.Generic.IEnumerable,System.Func)' 和'System.Linq.Enumerable.OrderBy(System.Collections.Generic.IEnumerable,System.Func)'

The call is ambiguous between the following methods or properties: 'System.Linq.Enumerable.OrderBy<string,int>(System.Collections.Generic.IEnumerable<string>, System.Func<string,int>)' and 'System.Linq.Enumerable.OrderBy<string,int>(System.Collections.Generic.IEnumerable<string>, System.Func<string,int>)'

我尝试了下面的建议,不幸的是没有运气.同时,我通过删除对 System.Core 的引用解决"了这个问题.这样我就可以使用 ReSharper DLL 文件提供的扩展.

I tried the suggestion below, unfortunately without luck. In the meanwhile, I "solved" the problem by removing references to System.Core. This way I could use the extensions provided by ReSharper DLL files.

上传了一个示例程序,其中我刚刚导入了我需要的 ReSharper DLL 文件.我将 System.Core 的别名更改为 SystemCore,添加了 extern alias 指令,但它仍然不起作用.如果我错过了什么,请告诉我.附言引用的是安装在 "C:Program FilesJetBrainsReSharperv4.1..." 中的默认目录中的 ReSharper v4.1 DLL 文件.

I uploaded a sample program where I just imported the ReSharper DLL files I needed. I changed the alias of System.Core to SystemCore, added the extern alias directive, but it still didn't work. If I missed something, please let me know. P.S. The references are to ReSharper v4.1 DLL files installed in the default directroy in "C:Program FilesJetBrainsReSharperv4.1...".

推荐答案

这不再是问题,因为我能够使用 ReSharper DLL 文件提供的 LINQ 扩展,即使是针对 .NET 3.0.

This is no longer an issue, since I am able to use the LINQ extensions, as provided by ReSharper DLL files, even while targeting .NET 3.0.

>

先生飞碟又是对的!我能够使用完整的 LINQ 语法,同时在项目的属性中针对 .NET 3.0 而不是引用 System.Core!

Mr. Skeet was right again! I am able to use full LINQ syntax, while targeting .NET 3.0 in the project's properties and not referencing System.Core!

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

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