0

How do i programmatically find list of all the controllers in a particular area ?

I did a Google search, but was not able to find anything relevant to it.

Since all the Controller to a particular area lies in a fixed namespace, i am thinking to find all controller that belongs in that namespace using reflection. Is there any other possible way ?

Parimal Raj
  • 20,189
  • 9
  • 73
  • 110

1 Answers1

1

See Getting all types in a namespace via reflection

Can add a statement to that inner query like so...

string @namespace = "MyApp.Areas.Admin.Controllers";
var q = from t in Assembly.GetExecutingAssembly().GetTypes()
        where t.IsClass && t.Namespace == @namespace 
        && typeof(t).IsSubclassOf(typeof(Controller))
        select t;
Community
  • 1
  • 1