public void Compile() { try { IsCompiled = false; _CompiledType = null; if (!string.IsNullOrEmpty(Content)) { var modelType = ModelType; if (_RazorIgnoreModelType || modelType == null) { Compile(typeof(DynamicObject)); } else { RazorService.Compile(Content, modelType, FullName.ToLower()); _CompiledType = modelType; } IsCompiled = true; } } catch (Exception ex) { ex.Log(ex.ToString(), Category.Debug); throw LangTexts.Current.GetFormatLangText("9010", "模板[{0}]编译时出错:\r\n{1}", FullName, ex.Message) .CreateException(); } }
public string Render(object model) { var lastDate = LastChanged; if (!CheckExists()) { throw LangTexts.Current.GetFormatLangText("9011", "模板文件[{0}]加载失败", FullName) .CreateException(); } if (_RazorIgnoreCompile) { if (lastDate.Ticks != LastChanged.Ticks) { Content = LoadContent(); } if (_RazorIgnoreModelType) { RemoveContentModel(); } return(RazorService.Parse(Content, model)); //return RazorService.Parse(; } if ((!IsCompiled) || lastDate.Ticks != LastChanged.Ticks) { Compile(); } if (IsCompiled) { return(RazorService.Run(FullName.ToLower(), model)); } return(null); }
private void Compile(Type type) { RemoveContentModel(); RazorService.Compile(Content, type, FullName.ToLower()); _CompiledType = type; }