volkovku / RazorTemplates

Open source templating engine based on Microsoft's Razor parsing engine. Thread safe. Allows run Razor templates outside ASP.Net MVC Projects.
Microsoft Public License
99 stars 32 forks source link

Unable to customize the base template #9

Closed gtemkin closed 11 years ago

gtemkin commented 11 years ago

I am trying to use a customized base class for the templates, but it results in an error when rendering the template as the base class in the generated code is still the default TemplateBase:

public abstract class MyTemplateBase : RazorTemplates.Core.TemplateBase
{
}

 RazorTemplates.Core.Template
                        .WithBaseType<MyTemplateBase>(t => t.Model = model)
                        .Compile("test").
                        .Render(model);

The generated code is:

namespace RazorTemplates {
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public class Template_1 : RazorTemplates.Core.TemplateBase {

       public Template_1() {
        }

        public override void Execute() {
           WriteLiteral("test");
        }
    }
}

As you can see the TemplateBase is still being used and that causes the following class cast exception during the rendering: Unable to case object of type 'RazorTemplates.Template_1' to type 'MyTemplateBase'

volkovku commented 11 years ago

Hi. I has fix this issue just now in nuget package RazorTemplates 1.1.3 (https://www.nuget.org/packages/RazorTemplates/1.1.3)