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

Improve SA1129 code fix for enum types #1972

Closed
sharwell opened this issue Dec 18, 2015 · 5 comments
Closed

Improve SA1129 code fix for enum types #1972

sharwell opened this issue Dec 18, 2015 · 5 comments
Assignees
Milestone

Comments

@sharwell
Copy link
Member

Currently the SA1129 code fix replaces new TaskState() with default(TaskState). An improved code fix for enum types would be the following:

  • If a single member Member in the enum declaration T has the value 0, replace new T() with T.Member
  • Otherwise, replace new T() with default(T) (i.e. fall back to the current behavior)
@sharwell sharwell added this to the 1.1.0 milestone Dec 18, 2015
@nbarbettini
Copy link
Contributor

For this and #1973, does it makes sense to just keep expanding the existing code fix with additional branches? Or should this be split into separate diagnostics/fixes?

@vweijsters
Copy link
Contributor

Either way you will have to create additional branches, as splitting into separate diagnostics/fixes will require exceptions to be added to the current implementation.

I would therefore prefer to go with extending the existing code fix, as adding exceptions for more specific diagnostics / fixes have not been problem free (For examples I'm thinking of SA1003 and SA1020-SA1024, but there are more).

@nbarbettini
Copy link
Contributor

Grabbing this.

@nbarbettini
Copy link
Contributor

@sharwell To clarify, do you mean "enum declaration T has only one member", or "enum declaration T has one member with value 0, among many members"?

@sharwell
Copy link
Member Author

I meant the latter. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants