c# – PostSharp:使用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
    }
}

现在我正在上课,而且我添加了我的属性

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_方法获取我想要的数据:

foreach (PropertyInfo pi in typeof(T).GetProperties())
        {
            var entityAttribute = (MyAttribute)(typeof(T).getmethod("get_" + pi.Name).GetCustomAttributes(typeof(MyAttribute),true).FirstOrDefault());
        }

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...