/// <summary>Prepares the template.</summary> /// <param name="assemblyPath">The assembly path.</param> /// <param name="typeName">Name of the type.</param> /// <param name="viewBag">The view bag.</param> /// <param name="templateCache">The template cache.</param> /// <param name="encoding">The encoding.</param> private TemplateBase PrepareTemplate(string assemblyPath, string typeName, DynamicViewBag viewBag, TemplateCache templateCache, TemplateEncoding encoding = TemplateEncoding.Html) { var type = GetTemplateType(assemblyPath, typeName); var templateInstance = Activator.CreateInstance(type); if (templateInstance is TemplateBase) { var template = (TemplateBase)templateInstance; template.Encoding = encoding; template.ViewBag = viewBag; template.TemplateResolver = tpl => { string tplAssemblyPath = templateCache.Get(tpl, template: null, timestamp: null); if (String.IsNullOrWhiteSpace(tplAssemblyPath)) { return(null); } var layoutType = GetTemplateType(tplAssemblyPath, templateNamespace + "." + tpl); return(Activator.CreateInstance(layoutType) as ITemplate); }; return(template); } throw new ArgumentException("Invalid template type!"); }
/// <summary>Renders the template with the given model.</summary> /// <typeparam name="T">Type of the model.</typeparam> /// <param name="assemblyPath">The assembly path.</param> /// <param name="typeName">Name of the type.</param> /// <param name="model">The model.</param> /// <param name="viewBag">The view bag.</param> /// <param name="templateCache">The template cache.</param> /// <param name="encoding">The encoding.</param> internal string RenderTemplateInternal <T>(string assemblyPath, string typeName, T model, DynamicViewBag viewBag, TemplateCache templateCache, TemplateEncoding encoding = TemplateEncoding.Html) { var template = PrepareTemplate(assemblyPath, typeName, viewBag, templateCache, encoding) as ITemplate <T>; template.Model = model; return(template.Render()); }