ITemplateContext ctx = new TemplateContext();
List<Orders> ProductList = new List<Orders> {
new Orders {OrderId = 1,ProductName="Some name",Quantity =30},
new Orders {OrderId = 1,ProductName="Some name1",Quantity =30},
new Orders {OrderId = 1,ProductName="Some name2",Quantity =30} };
ctx.DefineLocalVariable("context", new LiquidCollection(ProductList));
使用列表定义液体收集会引发错误。是否可以将T类型的通用集合定义为ITemplateContext-> LocalVariable
答案 0 :(得分:0)
ITemplateContext ctx = new TemplateContext();
List<Orders> ProductList = new List<Orders>
{
new Orders {OrderId = 1,ProductName="Some name",Quantity =30},
new Orders {OrderId = 1,ProductName="Some name1",Quantity =30},
new Orders {OrderId = 1,ProductName="Some name2",Quantity =30}
};
ctx.DefineLocalVariable("context", ProductList.ToLiquid());
使用Liquid.NET.Utils;