11
をOnMethodInvocationAspect使用している場合、カスタム属性が削除されている私は、このようないくつかの側面を持っている:はPostSharp:
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
}
}
は今、私は私のクラスを抱えている、と私はそれに私の属性を追加します。
class MyClass
{
[MyAttribute(0x10)]
public int MyProp { get; set; }
}
すべて正常に動作します。しかし、私はオフセットを得るためにリフレクションを使いたいと思っています。私がしたとき
typeof(MyClass).GetProperty("MyProp").GetCustomAttributes(true);
何も返されません。元のオフセット値(私の属性のプロパティ)にはどうすればアクセスできますか?
まずようなあなたの属性定義に属性を追加します:
[MulticastAttributeUsage(MulticastTargets.Method, PersistMetaData=true)]
public class MyAttribute : OnMethodInvocationAspect
そして私は私が望むデータを取得するために私の財産のget_メソッドメソッドを呼び出すことができます
うーんは –
:-)まだ質問のおかげで、私自身の答えを受け入れることができないと答えて:) –
おかげで男を。同様の問題がありました...それは私の地獄を混乱させていました... –