Search code examples
c#stringtemplate

StringTemplate ListDictionary Iteration


I'm trying to iterate over a ListDictionary (C# StringTemplate) in a template and have each list item invoke another template:

DataDefAssign(cols) ::=
<<
<cols.keys: { k | <PropDef(name=<k>, type=<cols.(k)>) }>
>>

The above template does not generate anything. If I inline an anonymous template instead of trying to invoke the PropDef template it works as expected. Does the iteration only allow anonymous templates?


Solution

  • I had a syntax issue. The iteration should be:

    <cols.keys: { k | <PropDef(name=k, type=cols.(k))> }>
    

    Thanks to [email protected] for pointing this out on the StringTemplate list.