'T4 Template not working with List as a parameter

I have a T4 template.

<#@ template language="C#" #>
<#@ import namespace="System.Collections.Generic"#>
<#@parameter name="Stats" type="System.Collections.Generic.List<SiteStat>" #>
<#@parameter name="Cnt" type="System.Int32" #>

    This is a test.  Why is this not working <#= Cnt #>
    <table>
        <# foreach (SiteStat stat in Stats)
           { #>
             <tr><td>Test name <#= stat.node #> </td>
                 <td>Test value <#= stat.region #> </td> </tr>
        <# } #>
     </table>

The simple integer is passing into the system fine but the more complex List is not.

It does not generate any content inside the table tags.

Edit 4/26/2021: My SiteStat is defined as follows

namespace ScheduledJobsService
{
    [Serializable]
    public struct SiteStat
    {
        public string region { get; set; }
        public string district { get; set; }
        public string system { get; set; }
        public string node { get; set; }
        public float a1score { get; set; }
        public float a1delta { get; set; }
        public float a7score { get; set; }
        public float a7delta { get; set; }
        public SiteStat(string region, string district, string system, string node, float a1score, float a1delta, float a7score, float a7delta)
        {
            this.region = region;
            this.district = district;
            this.system = system;
            this.node = node;
            this.a1score = a1score;
            this.a1delta = a1delta;
            this.a7score = a7score;
            this.a7delta = a7delta;
        }
    }
}

I tried using ScheduledJobsService.SiteStat inside my teplate as so

<#@parameter name="Stats" type="System.Collections.Generic.List<ScheduledJobsService.SiteStat>" #>

But it wont compile claiming that SiteStat does not exist in the ScheduledJobsService namespace



Solution 1:[1]

At the end of the .tt file add your parameters as public class members inside a "Class feature control block". This block must go to the end of the file.

<#+
public SiteStat Stats{ get; set; }
#>

you can use your template as follows:

YourTemplate t = new YourTemplate
{
    Stats = yourStatsObj
};

For more information regarding the T4 syntax, see MSDN article Writing a T4 Text Template. Writing a T4 Text Template

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1