public ITemplate Compile <T>(string template) { var combine = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, template + "." + EXT); try { var t = _compiler.CreateTemplate(File.ReadAllText(combine), typeof(T)); return(new RazorTemplate(t)); } catch (TemplateCompilationException e) { var sb = new StringBuilder(); foreach (var compilerError in e.Errors) { sb.AppendLine(compilerError.ToString()); } throw new Exception(e.Message + sb.ToString(), e); } }
/// <summary> /// Gets an <see cref="ITemplate"/> for the specified template. /// </summary> /// <param name="template">The template to parse.</param> /// <param name="modelType">[Optional] The model to use in the template.</param> /// <param name="name">[Optional] The name of the template.</param> /// <returns></returns> internal ITemplate GetTemplate(string template, Type modelType = null, string name = null) { if (!string.IsNullOrEmpty(name)) { if (cache.ContainsKey(name)) { return(cache[name]); } } var instance = compiler.CreateTemplate(template, modelType); if (!string.IsNullOrEmpty(name)) { if (!cache.ContainsKey(name)) { cache.Add(name, instance); } } return(instance); }