简体   繁体   English

T4模板中的Lambda表达式

[英]Lambda Expressions in T4 Templates

Whilst putting together a T4 template I threw in a simple lambda expression: 在整理T4模板的同时,我抛出了一个简单的lambda表达式:

<#=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. 在lambda表达式的行上。

This has been checked outside of a template and works fine. 这已在模板外检查并正常工作。 Does T4 not support working with lambda expressions? T4不支持使用lambda表达式吗? If not, are there any other language features that are unsupported in the context of a T4 template? 如果没有,是否有任何其他语言功能在T4模板的上下文中不受支持?

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 . 如果在Visual Studio 2008中使用T4,请确保在模板指令中将C#编译器版本设置为3.5。 It uses 2.0 by default. 它默认使用2.0。

As a work around, you might put that code into an external class library, which you can then call from within the T4 template. 作为一种解决方法,您可以将该代码放入外部类库中,然后可以在T4模板中调用该类库。 I've had to do that a number of times. 我必须多次这样做。 Its not ideal, but it works. 它不理想,但它的工作原理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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