private static RazorEngine<RazorTemplateBase> CreateHost()
        {
            var host = new RazorEngine<RazorTemplateBase>();

            // add this assembly
            host.AddAssemblyFromType(typeof(ResultsParser));
            host.AddAssemblyFromType(typeof (AppConfiguration));

            return host;
        }
Exemplo n.º 2
0
        private static RazorEngine <RazorTemplateBase> CreateHost()
        {
            var host = new RazorEngine <RazorTemplateBase>();

            // add this assembly
            host.AddAssemblyFromType(typeof(ResultsParser));
            host.AddAssemblyFromType(typeof(AppConfiguration));

            return(host);
        }
Exemplo n.º 3
0
        public void ManualCompileAndRunTest()
        {
            RazorEngine <RazorTemplateBase> host = CreateHost();

            if (host == null)
            {
                Assert.Fail("Unable to create RazorEngine " + host.ErrorMessage);
            }

            Person person = new Person()
            {
                Name    = "Rick",
                Company = "West WInd",
                Entered = DateTime.Now,
                Address = new Address()
                {
                    Street = "32 Kaiea",
                    City   = "Paia"
                }
            };

            // we have to explicitly add a reference to the model's assembly
            // if we're compiling manually - the compiler doesn't know about
            // the model.
            host.AddAssemblyFromType(person);

            string templateId = host.CompileTemplate(
                Templates.BasicTemplateStringWithPersonModel,
                "__RazorHost", "ManualCompileAndRun");

            if (templateId == null)
            {
                Assert.Fail("Unable to compile Template: " + host.ErrorMessage);
            }

            string result = host.RenderTemplateFromAssembly(templateId, person);

            if (result == null)
            {
                Assert.Fail(host.ErrorMessage);
                return;
            }

            Console.WriteLine(result);
            Console.WriteLine("--- Source Code ---");
            Console.WriteLine(host.LastGeneratedCode);
        }