Skip to content

Commit e01d308

Browse files
committed
2 parents d799548 + 3f5eae9 commit e01d308

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Alexander
3+
Copyright (c) 2020 Alexander Selishchev
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RazorEngineCore
2-
.NET6 Razor Template Engine. No legacy code.
2+
.NET6 Razor Template Engine. No legacy code. No breaking changes.
33
* .NET 6.0
44
* .NET 5.0
55
* .NET Standard 2.0
@@ -20,9 +20,14 @@ Every single star makes maintainer happy! ⭐
2020
Install-Package RazorEngineCore
2121
```
2222

23+
## Feature requests
24+
✅ Feel free to create new issues and vote for existing ones!
25+
26+
2327
## Articles
2428
* [CodeProject: Building String Razor Template Engine with Bare Hands](https://www.codeproject.com/Articles/5260233/Building-String-Razor-Template-Engine-with-Bare-Ha)
25-
29+
* [Razor syntax reference](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/razor?view=aspnetcore-6.0)
30+
2631
## Wiki
2732
* [Package comparison: RazorEngineCore / RazorLight / RazorEngine.NetCore](https://github.com/adoconnection/RazorEngineCore/wiki/Package-comparison)
2833
* [Strongly typed model](https://github.com/adoconnection/RazorEngineCore/wiki/Strongly-typed-model)

RazorEngineCore.Tests/TestCompileAndRun.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,24 @@ public async Task TestCompileAndRun_DynamicModel_PlainAsync()
157157
Assert.AreEqual("Hello Alex", actual);
158158
}
159159

160+
public struct Item
161+
{
162+
public string Name { get; set; }
163+
}
164+
165+
[TestMethod]
166+
public void TestCompileAndRun_StructList()
167+
{
168+
var eng = new RazorEngine();
169+
var model = new
170+
{
171+
Items = new[] { new Item { Name = "Bob" }, new Item { Name = "Alice" } }
172+
};
173+
var temp = eng.Compile("@foreach(var item in Model.Items) { @item.Name }");
174+
var result = temp.Run(model);
175+
Assert.AreEqual("BobAlice", result);
176+
}
177+
160178
[TestMethod]
161179
public void TestCompileAndRun_DynamicModel_Nested()
162180
{

RazorEngineCore/AnonymousTypeWrapper.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ public override bool TryGetMember(GetMemberBinder binder, out object result)
3939
result = new AnonymousTypeWrapper(result);
4040
}
4141

42-
bool isEnumerable = typeof(IEnumerable).IsAssignableFrom(type);
43-
4442
if (result is IDictionary dictionary)
4543
{
4644
List<object> keys = new List<object>();
@@ -58,9 +56,9 @@ public override bool TryGetMember(GetMemberBinder binder, out object result)
5856
}
5957
}
6058
}
61-
else if (isEnumerable && !(result is string))
59+
else if (result is IEnumerable enumer && !(result is string))
6260
{
63-
result = ((IEnumerable<object>)result)
61+
result = enumer.Cast<object>()
6462
.Select(e =>
6563
{
6664
if (e.IsAnonymous())

0 commit comments

Comments
 (0)