Closed afelsing closed 3 years ago
Hi, have a look at this unit test. When using dynamic model, you have to cast property to IEnumerable / ICollection / IList https://github.com/adoconnection/RazorEngineCore/blob/a2ae1f17de9553be86789d57b1d33b16df969a54/RazorEngineCore.Tests/TestCompileAndRun.cs#L540
RazorEngine razorEngine = new RazorEngine();
IRazorEngineCompiledTemplate template = razorEngine.Compile(
@"
@foreach (var item in ((IEnumerable<object>)Model.Numbers).OrderByDescending(x => x))
{
<p>@item</p>
}
");
string expected = @"
<p>3</p>
<p>2</p>
<p>1</p>
";
string actual = template.Run(new
{
Numbers = new List<object>() {2, 1, 3}
});
Assert.AreEqual(expected, actual);
Wonderful! Thank you much.
Hello! I am coming across an issue where extension methods are not being identified properly. In my sample below, I am trying to use LINQ's single, and the error is:
'System.Collections.Generic.List' does not contain a definition for 'First'
I've added the required assemblies using AddAssemblyReferenceByName() and assume it would load correctly. Yet I'm still getting the error.
When I call the extension method fully qualified, it works. ie, calling System.Linq.First(myList) instead of myList.Single().
Any guidance would be greatly appreciated!
Sample code: