0
是否可以通過字符串引用訪問集合項目而不是DotLiquid的索引偏移量?DotLiquid - 通過字符串索引器訪問集合元素?
public class MyItem
{
public string Name;
public object Value;
public MyItem(string Name, object Value)
{
this.Name = Name;
this.Value = Value;
}
}
public class MyCollection : List<MyItem>
{
public MyCollection()
{
this.Add(new MyItem("Rows", 10));
this.Add(new MyItem("Cols", 20));
}
public MyItem this[string name]
{
get
{
return this.Find(m => m.Name == name);
}
}
}
所以在普通的C#如果我創建MyCollection的類的實例,我可以像這樣訪問
MyCollection col =new MyCollection();
col[1] or col["Rows"]
我可以通過name元素山坳訪問[「行」]的元素在DotLiquid模板?如果是的話,我該如何實現這一點?