public static T LoadControl <T>([NotNull] this TemplateControl thisValue, string virtualPath, string invokeMethod, params object[] parameters) where T : class { T ctlToLoad; // If the invokeMethod is empty, I will go for the constructor if (string.IsNullOrEmpty(invokeMethod)) { Type type = GetTypeFromUrl(thisValue, virtualPath); ctlToLoad = thisValue.LoadControl(type, parameters) as T; } else { ctlToLoad = thisValue.LoadControl(thisValue.ResolveUrl(virtualPath)) as T; MethodInfo method = ctlToLoad?.AsType().FindMethod(invokeMethod, types: parameters.Types()); method?.Invoke(ctlToLoad, parameters); } return(ctlToLoad); }
public static T LoadObjectFromUrl <T>([NotNull] this TemplateControl thisValue, string virtualPath, Type baseType) where T : class { if (string.IsNullOrEmpty(virtualPath)) { return(null); } T result; Type btype = baseType ?? typeof(object); try { result = BuildManager.CreateInstanceFromVirtualPath(thisValue.ResolveUrl(virtualPath), btype) as T; } catch { result = null; } return(result); }