public async static Task <IModule> LoadModuleAsync(this ControllerBase ctrl, Type type, params object[] args) { if (type == null) { return(null); } var r = Activator.CreateInstance(type) as IModule; Task t = type.CallMethod(r, () => type.GetMethods().Where(it => it.Name == "Init" && it.ReturnType == typeof(Task)), (mtype, atype) => { if (typeof(ControllerBase).IsAssignableFrom(mtype) && !typeof(ControllerBase).IsAssignableFrom(atype)) { return(ctrl); } return(null); }, args) as Task; if (t != null) { await t; } if (r != null) { WebExModuleExtensions.RegisterModule(ctrl.ControllerContext.RequestContext.HttpContext.Items, r); } return(r); }
public static bool HasModule(this HtmlHelper helper, string moduleName, bool ignoreCase = false) { var mt = Type.GetType(moduleName, false, ignoreCase); if (mt != null) { return(helper.GetStorage().ContainsKey(WebExModuleExtensions.MakeViewDataKey(mt))); } return(false); }
public static void RegisterModule(IDictionary storage, IModule r) { if (r == null) { throw new ArgumentNullException(nameof(r)); } if (storage == null) { throw new ArgumentNullException(nameof(storage)); } storage[WebExModuleExtensions.MakeViewDataKey(r.GetType())] = new CachedModule(r); }
public static IModule LoadModule(IDictionary storage, Type type, params object[] args) { if (type == null) { return(null); } var r = type.CreateInstance(null, args) as IModule; if (r != null) { WebExModuleExtensions.RegisterModule(storage, r); } return(r); }
public static IModule LoadModule(this ControllerBase ctrl, Type type, params object[] args) { if (type == null) { return(null); } var r = type.CreateInstance((mtype, atype) => { if (typeof(ControllerBase).IsAssignableFrom(mtype) && !typeof(ControllerBase).IsAssignableFrom(atype)) { return(ctrl); } return(null); }, args) as IModule; if (r != null) { WebExModuleExtensions.RegisterModule(ctrl.ControllerContext.RequestContext.HttpContext.Items, r); } return(r); }
internal static CachedModule _GetModule(this ControllerBase ctrl, string moduleName, bool ignoreCase = false) { return(WebExModuleExtensions._GetModule(ctrl.ControllerContext.RequestContext.HttpContext.Items, ModulesCatalog.GetModule(ctrl.ControllerContext.HttpContext.Application, moduleName, ignoreCase))); }
public static IModule LoadModule(this ControllerBase ctrl, Type type, params object[] args) { if (type == null) { return(null); } var r = type.CreateInstance((mtype, atype) => { if (typeof(ControllerBase).IsAssignableFrom(mtype) && !typeof(ControllerBase).IsAssignableFrom(atype)) { return(ctrl); } return(null); }, args) as IModule; //foreach (var method in type.GetConstructors()) //{ // var methodParams = method.GetParameters(); // if (methodParams.Count() == 0) // { // r = Activator.CreateInstance(type) as IModule; // } // else // { // var params2Call = new object[methodParams.Count()]; // int j = 0; // for (int i = 0; i < params2Call.Length; i++) // { // var mtype = methodParams[i].ParameterType; // object arg = null; // if (args != null && args.Length > j) // arg = args[j]; // if (arg == null) // { // if (typeof(ControllerBase).IsAssignableFrom(mtype)) // params2Call[i] = ctrl; // if (args != null && args.Length > j) // j++; // } // else // { // if (mtype == arg.GetType()) // { // params2Call[i] = arg; // j++; // } // else if (typeof(ControllerBase).IsAssignableFrom(mtype) && !typeof(ControllerBase).IsAssignableFrom(arg.GetType())) // { // params2Call[i] = ctrl; // } // else // { // try // { // params2Call[i] = Convert.ChangeType(arg, mtype); // j++; // } // catch(Exception ex) // { // //eat an exception // } // } // } // } // r = Activator.CreateInstance(type, params2Call) as IModule; // } //} if (r != null) { WebExModuleExtensions.RegisterModule(ctrl.ControllerContext.RequestContext.HttpContext.Items, r); } return(r); }
public static bool HasModule(this HtmlHelper helper, Type module) { return(helper.GetStorage().ContainsKey(WebExModuleExtensions.MakeViewDataKey(module))); }
internal static CachedModule _GetModule(this HtmlHelper helper, string moduleName, bool ignoreCase = false) { return(WebExModuleExtensions._GetModule(helper.ViewContext.RequestContext.HttpContext.Items, ModulesCatalog.GetModule(helper.ViewContext.HttpContext.Application, moduleName, ignoreCase))); }