液体C#上下文初始化为T类型的变量

时间:2019-03-14 07:45:28

标签: c# liquid.net

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

1 个答案:

答案 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;