Je veux le faire, mais à obtenir cette erreur:Utilisation de méthodes d'extension dans .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]
J'ai vu des réponses ici qui dit, vous devez définir vous-même attribut.
Comment faire cela?
EDIT: C'est ce que j'ai:
[AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute
{
public static int MeasureDisplayStringWidth (this Graphics graphics, string text)
{
}
}
Non; vous avez besoin de * deux * classes; un pour l'attribut; un pour la (les) méthode (s) d'extension; mettra à jour. –