Passing data from upper foreach

时间:2015-10-06 08:14:35

标签: c# visual-studio-2015 code-generation t4

I have code for a T4 template that has two for each loops, and one is inside the other.

I am having an issue escaping the inner for each and pass data from the parent for each.

The image below demonstrates the variable data I am trying to pass from the parent for each to the child for each.

I have tried:

foreach (var prop in GetPropertiesNameOfClass(#><#=item #><#))
foreach (var prop in GetPropertiesNameOfClass(#>item<#))

when I transform the template it generates an error:

  • CS1525 error Invalid expression term ')'

  • CS1002 error ; expected

enter image description here

1 个答案:

答案 0 :(得分:3)

You are already inside of <# #> context, so you does not need any additional escaping to refer to item variable in your code:

foreach (var prop in GetPropertiesNameOfClass(item))