Question

Hi I seem to be having some problem on a T4 template.Here is my code:

  private void ResolveComplexType(PropertyInfo propertyInfo)
    {
        var property = propertyInfo.PropertyType;

        if (property.IsGenericType && property.GetGenericTypeDefinition() == typeof(List<>))
        {
            var argumentType = propertyInfo.PropertyType.GetGenericArguments()[0];
            PrintPropertiesInfo(argumentType);
        }
        else
        {
            PrintPropertiesInfo(property);
        }
    }

I am getting Identifier_Literal expected error on typeof(List<>)).I tested the exact same method on a C# class and it worked perfectly.

Does anyone know what the problem is?

EDIT

This is the error:

Error 2 Identifier_Literal expected

Was it helpful?

Solution

With this sample code I get no errors in T4 generation and compilation. Try to compare with your code.

<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" language="C#v3.5" debug="true" hostSpecific="true" #>
<#@ output extension=".cs" #>
<#@ Assembly Name="System.dll" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ Assembly Name="System.Windows.Forms.dll" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #> 
<#
   // insert your template code here the tempalte code will be syntaxhighlighted 
   // and you will have intellisense for all namespaces in the full edition
   string Greeting = "Hello";
#>
// This is the output code from your template
// you only get syntax-highlighting here - not intellisense
namespace MyNameSpace{
using System.Collections.Generic;
  class MyGeneratedClass{
     static void main (string[] args){
     if(typeof(List<>).ToString() == "yadayadayada" ){System.Console.WriteLine("isYadayadayada");}
       System.Console.WriteLine("<#= typeof(List<>) #>");
     }
  }
}

<#+
  // Insert any template procedures here
  void foo(){
    System.Console.WriteLine(typeof(List<>));
}
#>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top