Skip to content

Template Base / static typing #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
roja opened this issue Mar 4, 2020 · 1 comment
Closed

Template Base / static typing #7

roja opened this issue Mar 4, 2020 · 1 comment

Comments

@roja
Copy link
Contributor

roja commented Mar 4, 2020

Would it be possible to have a template base, as with various other Razor engines, to allow the model passed in to be statically typed?

i.e.

https://github.com/toddams/RazorLight#enable-intellisense-support
https://antaris.github.io/RazorEngine/IntellisenseAndResharper.html

@adoconnection
Copy link
Owner

adoconnection commented Mar 4, 2020

It is there, though the usage is a little bit different: you have to specify template base type + model type instead of model type only. It is much cooler because you are free to add any extra helpers to template (see #6 (comment))

string content = "Hello @Model.Name";

// yeah, heavy definition
RazorEngineCompiledTemplate<RazorEngineTemplateBase<TestModel>> template = razorEngine.Compile<RazorEngineTemplateBase<TestModel>>(content);

string result = template.Run(instance =>
{
    instance.Model = new TestModel()
    {
        Name = "Hello",
        Items = new[] {3, 1, 2}
    };
});

Console.WriteLine(result);

Make sure to update to
Install-Package RazorEngineCore -Version 2020.3.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants