扩展方法无法识别 [英] Extension Methods not Recognized

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

问题描述

什么是需要有当进口组装存在,它荣幸的扩展方法?我建之一的一个类库项目,但它并不在我的web项目,引用库的认可。在库中的所有其他类和方法很荣幸也可见,但这个扩展的方法是没有的。该库中使用时的扩展方法是可见的。

What is necessary to have an extension method honored when it exists in an imported assembly? I built one in a class library project but it is not recognized in my web project which references the library. All the other classes and methods in the library are honored and visible but this extension method is not. The extension method is visible when used within the library.

推荐答案

引用含有扩展方法一类的程序集是不够的。您需要导入包含在每个源文件要使用的扩展方法的类的命名空间。

Referencing an assembly containing a class with extension methods is not enough. You need to import the namespace containing the class in each of your source file where you want to use the extension methods.

例如,使用LINQ到对象,你需要引用 System.Core程序集并导入 System.Linq的命名空间(其中包含与LINQ扩展方法可枚举类):

For example, to use LINQ-to-objects, you need to reference the System.Core assembly and import the System.Linq namespace (which contains the Enumerable class with the LINQ extension methods):

using System.Linq;

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

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