dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.19k stars 9.93k forks source link

Please add support for constants for @page directive #54126

Open macias opened 6 months ago

macias commented 6 months ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

If you pick good book, or talk to somebody with a bit experience you will hear to not use magic symbols, like peppering your code with "44.5", instead you should define constant "DefaultSizeShoe" and then use this constant instead.

Yet, for some time @page supports only literal, not a symbol constant.

Describe the solution you'd like

Please support constants for @page, so one could write:

@page MyConstants.Counter

Additional context

There is interesting history for this request, because it was asked again and again, like here:

https://github.com/dotnet/aspnetcore/issues/15977

if it becomes a common feature request we'll certainly consider it

And the request is closed (it is not possible to upvote it or comment). So I wonder how on Earth we can make it "common feature request" if you disable any interaction.

2 years later:

https://github.com/dotnet/aspnetcore/issues/23195

you can achieve this by using @attribute [Route(Constants.PageRoute)] instead of @page and everything else should be the same.

Yes it works, but discoverability is... super low. Besides, if we humans have to replace one code for another, why computer cannot do this?

Bottom line is, if for any reason this feature is not possible for now, please, pretty please, leave it open, so other can read, comment, upvote, etc. Thank you.

lonix1 commented 6 months ago

Dupe https://github.com/dotnet/razor/issues/7519