【发布时间】:2015-10-09 19:03:22
【问题描述】:
我正在尝试访问应用于城堡拦截器中的方法的自定义属性,但方法 Attribute.GetCustomAttribute() 返回 null。
public class MyIntecept : Castle.DynamicProxy.IInterceptor
{
public void Intercept(IInvocation invocation)
{
// myAttr is null.
var myAttr = (MyAttribute)Attribute.GetCustomAttribute(
invocation.Method, typeof(MyAttribute));
}
}
[AttributeUsage(AttributeTargets.All, Inherited = true, AllowMultiple = true)]
public class MyAttribute : Attribute
{
readonly string _value;
public MyAttribute(string value)
{
this._value = value;
}
public string Value
{
get { return this._value; }
}
}
public interface IMyInterface
{
void Do();
}
public class MyClass : IMyInterface
{
[MyAttribute("MyValue")]
public void Do()
{
Console.WriteLine("Do");
}
}
如何获得“我的属性”?
附:我正在使用 Castle.Core 3.3.3
【问题讨论】:
标签: interceptor castle-dynamicproxy castle-windsor-3