Sử dụng Jon's suggestion of reflecting through the assembly, đây là một đoạn bạn có thể thấy hữu ích:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web.Mvc;
public class MvcHelper
{
private static List<Type> GetSubClasses<T>()
{
return Assembly.GetCallingAssembly().GetTypes().Where(
type => type.IsSubclassOf(typeof(T))).ToList();
}
public List<string> GetControllerNames()
{
List<string> controllerNames = new List<string>();
GetSubClasses<Controller>().ForEach(
type => controllerNames.Add(type.Name));
return controllerNames;
}
}
ASP.Net MVC là đã làm điều này, (tức là nó là cách tên điều khiển được phát hiện) nếu bạn có thể tận dụng việc thực hiện hiện tại trong MVC nó có lẽ sẽ giúp bạn tiết kiệm một chút thời gian. –
đó là một câu hỏi tuyệt vời ở đây - làm thế nào tôi sẽ làm điều đó? –