J'ai un aspect comme celui-ci:PostSharp: Les attributs personnalisés sont supprimés lors de l'utilisation OnMethodInvocationAspect
public class MyAttribute : OnMethodInvocationAspect
{
public int Offset { get; internal set; }
public MyAttribute(int offset)
{
this.Offset = offset;
}
public override void OnInvocation(MethodInvocationEventArgs eventArgs)
{
//do some stuff
}
}
Maintenant, je vais avoir ma classe, et j'ajouter mon attribut il:
class MyClass
{
[MyAttribute(0x10)]
public int MyProp { get; set; }
}
Fonctionne très bien. Pourtant, maintenant je veux utiliser la réflexion pour obtenir mon offset; quand je le fais
typeof(MyClass).GetProperty("MyProp").GetCustomAttributes(true);
Il ne retourne rien. Comment puis-je accéder à ma valeur Offset d'origine (la propriété de mon attribut)?
Hmm ne peut pas accepter ma propre réponse encore :-) Merci pour –
questions et réponses :) –
homme Merci. J'ai eu un problème similaire ... ça m'a dérouté ... –