我有一些这样的方面:
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
foreach (PropertyInfo pi in typeof(T).GetProperties()) { var entityAttribute = (MyAttribute)(typeof(T).getmethod("get_" + pi.Name).GetCustomAttributes(typeof(MyAttribute),true).FirstOrDefault()); }
原文地址:https://www.jb51.cc/csharp/97371.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。