Compare commits
2 Commits
72dbbde075
...
caac6c0d39
| Author | SHA1 | Date | |
|---|---|---|---|
| caac6c0d39 | |||
| 05a07ca5ea |
@ -45,6 +45,34 @@ namespace PSTW_CentralSystem.Controllers.API
|
||||
// Return the list as JSON
|
||||
return Json(controllerAndMethodList);
|
||||
}
|
||||
[HttpPost("GetListClassAndMethodInformation")]
|
||||
public async Task<IActionResult> GetListClassAndMethodInformation()
|
||||
{
|
||||
var controllerAndMethodList = new List<object>();
|
||||
|
||||
// Get the assembly containing the controllers
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
|
||||
// Get all types in the assembly (controllers will typically be in the "Controllers" namespace)
|
||||
//var controllerTypes = await Task.Run(() => assembly.GetTypes().Where(type => typeof(ControllerBase).IsAssignableFrom(type) && type.IsClass && type.Name.Contains("Controller") && type.Name != "AdminController") .ToList());
|
||||
var controllerTypes = await Task.Run(() => assembly.GetTypes().Where(type => typeof(ControllerBase).IsAssignableFrom(type) && type.IsClass && !type.Name.Contains("API") && !type.Name.Contains("Admin")).ToList());
|
||||
|
||||
// Iterate over the controller types and get their methods
|
||||
foreach (var controllerType in controllerTypes) {
|
||||
var methods = controllerType?.GetMethods(BindingFlags.Public | BindingFlags.Instance)
|
||||
.Where(m => m.DeclaringType == controllerType) // Filter methods declared directly in the controller (ignoring inherited ones)
|
||||
.Select(m => m.Name) // Get the method names
|
||||
.ToList();
|
||||
|
||||
controllerAndMethodList.Add(new
|
||||
{
|
||||
Controller = controllerType?.Name,
|
||||
Methods = methods
|
||||
});
|
||||
}
|
||||
// Return the list as JSON
|
||||
return Json(controllerAndMethodList);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user