T4MVC 2.6.65 和 UseLowercaseRoutes=true 错误
再会!
我正在使用来自 NuGet 的 2.6.65 的最新 T4MVC(从 2.6.64 升级),我已经设置
// If true, use lower case tokens in routes for the area, controller and action names
static bool UseLowercaseRoutes = true;
并且收到错误:
The expression being assigned to '....' must be constant ...\T4MVC.cs
这是触发错误的生成代码:
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public class ActionNameConstants {
public const string Calc = ("Calc").ToLowerInvariant();
}
这是一个错误吗?
Good day!
I'm using latest T4MVC from 2.6.65 from NuGet (upgraded from 2.6.64), I've set
// If true, use lower case tokens in routes for the area, controller and action names
static bool UseLowercaseRoutes = true;
And I got error:
The expression being assigned to '....' must be constant ...\T4MVC.cs
Here is the the generated code that triggers error:
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public class ActionNameConstants {
public const string Calc = ("Calc").ToLowerInvariant();
}
Is this a bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊抱歉,之前的更改破坏了它。我刚刚推出了新版本的 T4MVC (2.6.66),它解决了这个问题。嗯,它更像是一种解决方法,因为在使用 UseLowercaseRoutes 时它基本上不会生成常量标记。但这会让我们现在继续前进。
问题的根源是 C# 不支持在常量字符串中使用 .ToLowerInvariant() 。理想情况下,它只会在编译时对其进行评估,但它并不那么聪明:)
Ah sorry, the previous change broke it. I just pushed a new build of T4MVC (2.6.66) which addresses this. Well, it's more of a workaround as it basically doesn't generate the constant tokens when UseLowercaseRoutes is used. But that'll get us going for now.
The root of the problem is that C# doesn't support using .ToLowerInvariant() in constant strings. Ideally, it would just evaluate that at compile time, but it's not that smart :)