/// <summary> /// Discover all the api endpoints in an assembly. /// </summary> /// <returns></returns> public ApiControllersViewModel Discover() { ApiControllersViewModel result = new ApiControllersViewModel(); System.Type[] assemblyTypes = this.Assembly.GetTypes(); for (long i = 0; i < assemblyTypes.LongLength; i++) { System.Type assemblyType = assemblyTypes[i]; // get the controller base types if (assemblyType.BaseType == typeof(Microsoft.AspNetCore.Mvc.Controller) || assemblyType.BaseType?.BaseType == typeof(Microsoft.AspNetCore.Mvc.Controller)) { string controllerName = string.Empty; string controllerRoute = string.Empty; bool addController = false; addController = this.HasApiAttrs(assemblyType, out controllerName, out controllerRoute); if (addController == true) { ApiControllerModel apiController = new ApiControllerModel() { Name = controllerName, Route = controllerRoute }; MethodInfo[] methods = assemblyType.GetMethods(); // get the attributes foreach (MethodInfo method in methods) { ApiActionModel apiActionModel = this.GetApiActionModel(method, controllerRoute); if (apiActionModel != null) { apiController.Actions.Add(apiActionModel); } } // Remove the route info from the route its not needed anymore. if (apiController.Route.Contains("[action]")) { apiController.Route = apiController.Route.Replace("[action]", string.Empty); if (apiController.Route.EndsWith("/")) { apiController.Route = apiController.Route.Substring(0, apiController.Route.Length - 1); } } result.Controllers.Add(apiController); } } } return(result); }
/// <summary> /// Discover all the api endpoints in an assembly. /// </summary> /// <returns></returns> public ApiControllersViewModel Discover() { ApiControllersViewModel result = new ApiControllersViewModel(); System.Type[] assemblyTypes = this.Assembly.GetTypes(); for (long i = 0; i < assemblyTypes.LongLength; i++) { System.Type assemblyType = assemblyTypes[i]; // get the controller base types if (assemblyType.BaseType == typeof(Microsoft.AspNetCore.Mvc.Controller)) { string controllerName = string.Empty; string controllerRoute = string.Empty; bool addController = false; addController = this.HasApiAttrs(assemblyType, out controllerName, out controllerRoute); if (addController == true) { ApiControllerModel apiController = new ApiControllerModel() { Name = controllerName, Route = controllerRoute }; MethodInfo[] methods = assemblyType.GetMethods(); // get the attributes foreach (MethodInfo method in methods) { ApiActionModel apiActionModel = this.GetApiActionModel(method); if (apiActionModel != null) { apiController.Actions.Add(apiActionModel); } } result.Controllers.Add(apiController); } } } return(result); }