stringtemplate - perform iteration in StringTemplate4 (C#) -


in stringtemplate4 cheat sheet (http://www.antlr.org/wiki/display/st/stringtemplate+cheat+sheet), mentions perform iteration

<attribute:{anonymous-template}> apply anonymous template each element of attribute. iterated `it` attribute set automatically. 

i have tried below code:

        list<textparsetests.testmodel> data = new list<textparsetests.testmodel>();         (int = 0; < 10; i++)         {             textparsetests.testmodel model2 = new textparsetests.testmodel();             model2.name = i.tostring();             data.add(model2);         }           string template = @"testtemplate|| <list:{ [datalist <it.name>]  }> [end]";          template t = new template(template);         t.add("list", data.toarray());           var result = t.render();         sb.appendline(result); 

update 1

below testmodel data structure , related classes. using these just

    public class contactdetailstest     {         public string email { get; set; }         public string address1 { get; set; }     }      public class testmodel     {         public string name { get; set; }         public string surname { get; set; }         public contactdetailstest contactdetails { get; set; }          public testmodel()         {             this.contactdetails = new contactdetailstest();         }     } 

yet end result is:

"testtemplate||  [datalist ]   [datalist ]   [datalist ]   [datalist ]   [datalist ]   [datalist ]   [datalist ]   [datalist ]   [datalist ]   [datalist ]   [end]" 

it iterated 10 times, variable it not seem have been populated. ideas?

you need change template this

testtemplate|| <list:{x | [datalist <x.name>]  }> [end] 

as of documentation

<attribute:{x | anonymous-template}> apply anonymous template each element of attribute.   iterated value set argument x.  anonymous template references <x> access iterator value. 

you can set x like, it's place holder iterator.

the problem using stringtemplate3 cheatsheet instead of stringtemplate4 cheatsheet http://www.antlr.org/wiki/display/st4/stringtemplate+cheat+sheet


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -