Tôi muốn làm điều này, nhưng nhận được lỗi này:Sử dụng các phương pháp mở rộng trong .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]
Tôi đã thấy một số câu trả lời ở đây nói rằng, bạn phải xác định mình thuộc tính này.
Tôi làm như thế nào?
EDIT: Đây là những gì tôi có:
[AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute
{
public static int MeasureDisplayStringWidth (this Graphics graphics, string text)
{
}
}
Không; bạn cần * hai * lớp; một cho thuộc tính; một cho (các) phương pháp mở rộng; sẽ nâng cấp. –