I’ve got a T4 template that writes a DTO construct for my classes. I decided to add the following code to the template:
<# if( prop.TypeUsage.EdmType.Name.ToLower() == "datetime" ) { #>
<#= [DisplayFormat(DataFormatString = "{0:mm/dd/yyyy}")] #>
<# } #>
when I compile it I get an error saying: “) expected”. When I look at the intermediate code that T4 built I see the following:
#line 55 "C:\Users\Lou\Documents\Visual Studio 2010\Projects\...\DTO_Generator.tt" this.Write(Microsoft.VisualStudio.TextTemplating.ToStringHelper.ToStringWithCulture(//[DisplayFormat(DataFormatString = "{0:mm/dd/yyyy}")]));
Apparently the compiler is putting a “//” before the “[DisplayFormat(DataFormatString = “{0:mm/dd/yyyy}”)] ” that I want to insert which is removing the ‘)’ which is at the end of that line.
I’ve tried to escape and double the “[” which I assume is causing the problem.
Any ideas on how to avoid having T4 puting those “//” into the code?
Thanks.
I’m not sure I understand what you are trying to do. The
<#= ... #>code evaluates the...as a string and outputs it. If you explicitly want[DisplayFormat(DataFormatString = "{0:mm/dd/yyyy}")]to be output, then you should use: