Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer to introduce a variable even for constants #76907

Open
MartyIX opened this issue Jan 24, 2025 · 0 comments
Open

Offer to introduce a variable even for constants #76907

MartyIX opened this issue Jan 24, 2025 · 0 comments
Labels
Area-IDE Feature Request untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@MartyIX
Copy link
Contributor

MartyIX commented Jan 24, 2025

Summary

When one selects a constant in code and then presses CTR+., Visual Studio offers to create a constant for selected code. This is current behavior:

Image

I would be happy to be offered an option to create a variable as well. To phrase it differently, I miss the "Introduce Local" option.

Background and Motivation

So why one might want a variable instead of a constant? When I work on something, it happens that something that used to be a constant becomes a variable.

For example, one have an analyzer that checks lenghts of lines. One starts with a magic number 150 and it works pretty well for a long time but then one day another team wants to use that analyzer as well but they want 141 characters.

I'm aware that there is the "Introduce local constant for '1'" feature and it can certainly be used as a workaround but it requires more work for me "remove const keyword make the first letter of the variable to be in lowercase. So while doable, it's more manual work than to type "var" + copy value (i.e. 1 in this case).

Proposed Feature

Add "Introduce Local" option.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Feature Request untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

1 participant