简体   繁体   中英

Lambda Expressions in T4 Templates

Whilst putting together a T4 template I threw in a simple lambda expression:

<#=string.Join(",", updateFields.ConvertAll(field => field.Name).ToArray())#>

This causes the template to fail to generate with the error:

Compiling transformation: Invalid expression term '>'   

On the line with the lambda expression.

This has been checked outside of a template and works fine. Does T4 not support working with lambda expressions? If not, are there any other language features that are unsupported in the context of a T4 template?

Thanks!

If you are using T4 in Visual Studio 2008, make sure that you have C# compiler version set to 3.5 in the template directive . It uses 2.0 by default.

As a work around, you might put that code into an external class library, which you can then call from within the T4 template. I've had to do that a number of times. Its not ideal, but it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM