访问OperationInterceptor中的MethodInfo
我创建了几个自定义属性,将它们附加到处理程序中的方法中。自定义属性不仅仅是“标记器”,例如“RequiresAuthenticationAttribute”。一个简化的示例:
[EnforceParam("Account")]
在我的拦截器中,使用 EnforceParam 注释的方法调用该拦截器,我想访问值“Account”。我目前正在做的是这样的:
public override bool BeforeExecute(IOperation operation)
{
ReflectionBasedMethod method = (ReflectionBasedMethod)((MethodBasedOperation)operation).Method;
MethodInfo methodInfo = method.MethodInfo;
为了使其工作,我必须将“Method”属性添加到 OpenRasta 的 ReflectionBasedMethod 中。
可以在不破解 OpenRasta 的情况下完成同样的任务吗(顺便说一句,我使用的是 2.0)?
I created a couple of custom attributes that I attach to my methods in the handlers. The custom attributes are more than mere 'taggers' like e.g. 'RequiresAuthenticationAttribute'. A simplified example:
[EnforceParam("Account")]
In my interceptor, that gets called for methods annotated with EnforceParam, I'd like to get access to the value "Account". What I'm currently doing for that is this:
public override bool BeforeExecute(IOperation operation)
{
ReflectionBasedMethod method = (ReflectionBasedMethod)((MethodBasedOperation)operation).Method;
MethodInfo methodInfo = method.MethodInfo;
For that to work, I had to add the 'Method' property to OpenRasta's ReflectionBasedMethod.
Can the same be accomplished without hacking OpenRasta (I'm on 2.0 btw)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是错误的问题。您要寻找的很简单:
不支持向下转换,并且该操作应该仅有意反映操作及其输入。不要沮丧,它将会崩溃,并且不保证您的代码能够在碰巧使用 IMethod API 的一个版本之外工作,而 IMethod API 在某些时候会被重写/删除。
That's the wrong question. What you're looking for is simply:
Downcasting is not supported and the operation should only reflect an operation and its inputs, on purpose. Do not downcast, it will break and your code is not guaranteed to work beyond one version that happens to use the IMethod API, which is going at some point to be rewritten / removed.