public static string GeneratorCode(this Type type, string tempaltePath, object viewModel) { if (!RazorEngineEx.CreateEngineAfter) { RazorEngineEx.CreateEngine(); } string templateSource = type.ReadTemplate(tempaltePath); return(Engine.Razor.RunCompile(templateSource, tempaltePath, null, viewModel, null).Replace("'", "'").Replace(">", ">").Replace(""", "\"").Replace("<", "<")); }
public static string GeneratorCode(this string tempaltePath, object viewModel, Type viewModelType, string oldCustomCode) { string result; try { DynamicViewBag dynamicViewBag = new DynamicViewBag(); dynamicViewBag.AddValue("OldCustomCode", oldCustomCode); if (!RazorEngineEx.CreateEngineAfter) { RazorEngineEx.CreateEngine(); } string templateSource = File.ReadAllText(tempaltePath, EncodingEx.Utf8WithoutBom); result = Engine.Razor.RunCompile(templateSource, tempaltePath, viewModelType, viewModel, dynamicViewBag); result = result.Replace("'", "'").Replace(">", ">").Replace(""", "\"").Replace("<", "<").Replace("<pre>", "").Replace("</pre>", ""); } catch (Exception) { throw; } return(result); }