views:

35

answers:

1

I'm writing a method that just uses the ActionDescriptor property but I can't figure out how to avoid repeating the body of the method so that it can take either an ActionExecutingContext or an AuthorizationContext. Both of these types have an ActionDescriptor property, but they don't inherit it from a common type or interface that I can find.

A: 

Refactor the code that consumes the ActionDescriptor into its own static method somewhere, then call that method from within your OnActionExecuting() or OnAuthorization(), passing in the ActionDescriptor object.

Levi
Yeah, I did that, but there is still a little repeated code there... would like to just eliminate it entirely.
JoelFan
What's the repeated code? If the interesting logic consumes only the ActionDescriptor object, then it can be refactored into a single non-duplicated method that takes only that as a parameter. You'd still need to call it from both OnActionExecuting() and OnAuthorization(), but that doesn't really count as duplicate code. :)
Levi
Yeah, it's not much... just the line that gets the ActionDescriptor... but it seems not quite ideal
JoelFan