Reputation: 18065
I'm writing an attribute where I want to access a method on the class that the controller that has the attribute on one of its actions derives from. That's quite a mouthful, so let me explain:
protected bool IsSearchEngine()
(the base class itself derives from Controller
)ActionFilterAttribute
and overloads OnResultExecuting
.OnResultExecuting
method has a ResultExecutingContext
parameter.How can I access IsSearchEngine()
through the ResultExecutingContext
?
UPDATE: So far, I've gotten the compiler and Intellisense to accept this:
(filterContext.Controller as MyAssembly.Controllers.BaseControllerClass).IsSearchEngine()
Is that the right way to do this? I haven't tested it yet.
Upvotes: 0
Views: 1878
Reputation: 18419
By casting the resultExecutingContext.Controller
to BaseController
you can access through all Property and Methods of your base controller, but the protection level of your Method IsSearchEngine()
you cannot access it. If you declared your IsSerchEngine()
by public
you can just call it as ((BaseController)resultExecutingContext.Controller).IsSearchEngine()
Upvotes: 1