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

Add refactoring to convert between default literal/expression and other literals #25556

Open
Neme12 opened this issue Mar 17, 2018 · 3 comments
Labels
Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@Neme12
Copy link
Contributor

Neme12 commented Mar 17, 2018

from #25456

Generally speaking, this fixer should offer null as a simplification of default(T) when T is a reference type or nullable value type, 0m when T is decimal, 0 when T is another numeric type, false if T is bool, and '\0' if T is char.

It would be nice to have refactorings to

  1. convert from a default literal / default expression to another literal (such as 0, null or false)
  2. to convert such literals back to a default literal, or if the user's preference of using default literals is set to false, a default expression instead
@jcouv jcouv added the Area-IDE label Mar 18, 2018
@jinujoseph jinujoseph added this to the Unknown milestone Apr 20, 2018
@Neme12 Neme12 changed the title Add code fix to convert between default literal/expression and other literals Add refactoring to convert between default literal/expression and other literals Oct 10, 2018
@sharwell sharwell added help wanted The issue is "up for grabs" - add a comment if you are interested in working on it Feature Request labels Oct 30, 2018
@sharwell
Copy link
Member

sharwell commented Oct 30, 2018

We covered this in today's design review, and felt that a conversion from default or default(T) to a literal value (where available) would be reasonable. It did not seem advantageous to offer the reverse as a refactoring, and it also wouldn't need to be an analyzer or have a code style preference associated with it.

@Neme12
Copy link
Contributor Author

Neme12 commented Oct 30, 2018

@sharwell Should there then be a separate refactoring from default or default(T) to a literal, or could that be implemented as part of #30464?

@Neme12
Copy link
Contributor Author

Neme12 commented Oct 30, 2018

The obvious implementation of "inline constant" would cover this as well (expect for all the special cases for enums/CancellationToken).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
None yet
Development

No branches or pull requests

4 participants