3

再会!

我正在使用来自 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();
    }

这是一个错误吗?

4

1 回答 1

2

啊抱歉,之前的更改破坏了它。我刚刚推出了一个新版本的 T4MVC (2.6.66) 来解决这个问题。好吧,这更像是一种解决方法,因为它在使用 UseLowercaseRoutes 时基本上不会生成常量标记。但这会让我们暂时继续前进。

问题的根源是 C# 不支持在常量字符串中使用 .ToLowerInvariant() 。理想情况下,它只会在编译时评估它,但它并不那么聪明:)

于 2011-12-22T18:06:03.343 回答