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)?
That's the wrong question. What you're looking for is simply:
var attribute = operation.FindAttribute<EnforceParamAttribute>()
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.