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

Problems using Linq #8

Closed mcintyre321 closed 11 years ago

mcintyre321 commented 11 years ago
    var template = Template
        .WithBaseType<TemplateBase>()
        .AddNamespace("System.Linq")
        .Compile<List<string>>("Hello @(Model.First())");
    Console.WriteLine(template.Render(new List<string>{"Hello", "World" }));

results in

System.Collections.Generic.List<string>' does not contain a definition for 'First'

I would also like to be able to use a lambda expression in there:

.Compile<List<string>>("Hello @(Model.First(x => x == \"World\"))");

but that results in

TemplateCompilationException: An errors was occured on template compilation:

c:\Users\harrym\AppData\Local\Temp\e166e141b2b44323ae03d4e437e53805\ixmiyqap.0.cs(27,21) : error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

Template source code:
Hello @(Model.First(x => x == "World"))!

Any ideas how to make this work?

volkovku commented 11 years ago

Hi, Harry, this is a bug. I was fixed it right now in RazorTemplates 1.1.2.