/// <summary> /// Generates a controller context to be passed to the controller. /// </summary> /// <param name="attr">The controller's class attribute.</param> /// <returns>The ControllerContext to be passed to the controller.</returns> private ControllerContext GetControllerContext(RestQueryControllerAttribute attr) { return(new ControllerContext() { Log = this.log, RestClient = this.restClient, ControllerBaseAddress = $"{this.restQueryConfig.BaseAddress}{attr.Name}" }); }
/// <summary> /// Initiate the controller list. Use reflection to capture controllers and add them to the dictionary. /// A Controller must have the class attribute RestQueryController. /// </summary> private void InitControllers() { Assembly[] assarr = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly ass in assarr) { try { Type[] typearr = ass.GetTypes(); foreach (Type type in typearr) { if (!type.IsClass) { continue; } IEnumerable <Attribute> attrArr = type.GetCustomAttributes(); if (attrArr == null) { continue; } foreach (Attribute attr in attrArr) { RestQueryControllerAttribute item = attr as RestQueryControllerAttribute; if (item == null) { continue; } item.ControllerType = type; this.controllers.Add(item); } } } catch { // In some situation an exception is raised which is not harmfull. this.log.Warn("Error while browsing assemblies for controllers (harmless)"); } } }