Esempio n. 1
0
        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("&#39;", "'").Replace("&gt;", ">").Replace("&quot;", "\"").Replace("&lt;", "<"));
        }
Esempio n. 2
0
        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("&#39;", "'").Replace("&gt;", ">").Replace("&quot;", "\"").Replace("&lt;", "<").Replace("<pre>", "").Replace("</pre>", "");
            }
            catch (Exception)
            {
                throw;
            }
            return(result);
        }