gpt4 book ai didi

c# - 从 CaSTLe Windsor 拦截器访问方法的自定义属性

转载 作者:太空狗 更新时间:2023-10-30 00:36:13 25 4
gpt4 key购买 nike

我正在尝试访问应用于城堡拦截器中方法的自定义属性,例如:

[MyCustomAttribute(SomeParam = "attributeValue")]
public virtual MyEntity Entity { get; set; }

使用以下代码:

internal class MyInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
if (invocation.Method.GetCustomAttributes(typeof(MyCustomAttribute), true) != null)
{
//Do something
}
}
}

调用方法时拦截器正常触发,但此代码不返回自定义属性。我怎样才能做到这一点?

最佳答案

为此尝试使用 Attribute.GetCustomAttribute(...) 静态方法。这很奇怪,但这两种方法有时会出于某种奇怪的原因返回不同的结果。

关于c# - 从 CaSTLe Windsor 拦截器访问方法的自定义属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2536675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com