相关疑难解决方法(0)

在.NET 2.0中使用扩展方法?

我想这样做,但得到这个错误:

错误1无法定义新的扩展方法,因为无法找到编译器所需的类型"System.Runtime.CompilerServices.ExtensionAttribute".您是否缺少对System.Core.dll的引用?[剪了一些路径]

我在这里看到一些答案说,你必须自己定义这个属性.

我怎么做?

编辑:这就是我所拥有的:

[AttributeUsage ( AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method )]
public sealed class ExtensionAttribute : Attribute
{
    public static int MeasureDisplayStringWidth ( this Graphics graphics, string text )
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# extension-methods

32
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

c# ×1

extension-methods ×1