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

Natively supporting typed template #5

Closed Julion closed 11 years ago

Julion commented 11 years ago

Hi,

I made a few modifications to natively support a typed view model, instead of having a dynamic Model property or a custom template inheriting from TemplateBase. This is particularly usefull if you extract your template in a cshtml file, allowing you to get syntax completion within visual studio.

The implementation is not what I would call clean (I had to use method/property hiding) but doing it the proper way would break the compatibility of your API.

You can have a look at the unit test to see how to use the typed template.

Regards,

Julien

Julion commented 11 years ago

There is bug in the suggested implementation. I'll get back to you in a few minutes with another pull request fixing it

Julion commented 11 years ago

This version works as expected for typed model, expando objects and anonymous types