T4MVC 2.6.65 和 UseLowercaseRoutes=true 错误

发布于 2024-12-22 15:37:07 字数 570 浏览 3 评论 0原文

再会!

我正在使用来自 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女情怀诗 2024-12-29 15:37:07

啊抱歉,之前的更改破坏了它。我刚刚推出了新版本的 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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文