【发布时间】:2009-10-05 21:54:11
【问题描述】:
我想这样做,但收到此错误:
错误 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 )
{
}
}
【问题讨论】:
-
否;你需要两个类;一个用于属性;一种用于扩展方法;会更新。
标签: c# .net extension-methods