English 中文(简体)
C 模棱两可的推广方法
原标题:C# ambiguous extension methods

LinqKit有一个延伸方法ForEach >:IE amountable,与System发生冲突。 收集。 Generic.IE amountable

Error   4   The call is ambiguous between the following methods or properties: 
 LinqKit.Extensions.ForEach<Domain>(System.Collections.Generic.IEnumerable<Domain>, System.Action<Domain>)  
and 
 System.Linq.EnumerableExtensionMethods.ForEach<Domain>(System.Collections.Generic.IEnumerable<Domain>, System.Action<Domain>) 

How can I get rid of this error?

最佳回答

。 两者都来自外部参考资料。

您只应考虑使用其中一种文字,即增加<代码>的参考。 缩略语

(这之前,是使用与框架相同的名称空间造成问题的原因之一——在这种情况下,是<代码>的作者。) 无数ExtensionMethods将其列入System.Linq,这将引起你在使用Linq和你有名称空间发生冲突时的任何问题。

如果你真的需要使用这一方法,那么你就不得不直接使用这种方法,而不是使用推广方法,即:

LinqKit.Extensions.ForEach(collection, action);

或:

System.Linq.EnumerableExtensionMethods.ForEach(collection, action);

尽管如此,我个人将利用每一条路程处理这些要素。

问题回答

你完全需要像错误信息那样,完全限定你所呼吁的方法。

因此,不使用

ForEach<Domain>( ... );

用途

LinqKit.Extensions.ForEach<Domain>( ... );




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签