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.
views:
35answers:
1
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
2009-12-28 03:50:32
Yeah, I did that, but there is still a little repeated code there... would like to just eliminate it entirely.
JoelFan
2009-12-28 15:38:31
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
2009-12-28 17:00:04
Yeah, it's not much... just the line that gets the ActionDescriptor... but it seems not quite ideal
JoelFan
2009-12-29 05:50:15