我想做这件事,但是出现了这个错误:
Error 1 Cannot define a new extension method because the compiler required type 'System.Runtime.CompilerServices.ExtensionAttribute' cannot be found. Are you missing a reference to System.Core.dll? [省略一些路径信息]
我看到有些答案在这里说,你必须自己定义这个属性。
我该怎么做呢?
编辑:这是我拥有的:
[AttributeUsage ( AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method )]
public sealed class ExtensionAttribute : Attribute
{
public static int MeasureDisplayStringWidth ( this Graphics graphics, string text )
{
}
}