我想這樣做,但得到這個錯誤:在.NET 2.0中使用擴展方法?
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? [snipped some path stuff]
我這裏,說看到了一些答案,你必須定義此屬性自己。
我該怎麼做?
編輯:這是我有:
[AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute
{
public static int MeasureDisplayStringWidth (this Graphics graphics, string text)
{
}
}
否;你需要*兩個*類;一個用於屬性;一個用於擴展方法;將更新。 – 2009-10-06 05:06:21