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

C# 6 migration aids #19

Open
sharwell opened this issue Nov 17, 2014 · 3 comments
Open

C# 6 migration aids #19

sharwell opened this issue Nov 17, 2014 · 3 comments

Comments

@sharwell
Copy link
Member

This will be a common request I imagine. It would be cool to have a collection of diagnostics/code fixes that identify code that can use new C# 6 features and automatically change them.

This is a prime candidate for implementing multiple diagnostics within a single repository.

@sharwell
Copy link
Member Author

This functionality can be selectively enabled by the following steps.

  1. In DiagnosticAnalyzer.Initialize(AnalysisContext), register a compilation start action by calling context.RegisterComplationStartAction.
  2. In the implementation of the handler, cast the CompilationStartAnalysisContext.Compilation value to a CSharpCompilation. If the LanguageVersion property is less than CSharp6, return immediately.
  3. Register any remaining handlers in the compilation start action instead of placing them in the Initialize method.

The diagnostic will be automatically disabled for any project containing a line like the following:

<PropertyGroup>
  <LangVersion>5</LangVersion>
</PropertyGroup>

@BillWagner
Copy link
Contributor

Here is another good example of where I'd like to see these labeled as "refactoring" rather than "code fix".

The C# 1.x styles are still valid, correct, and supported. There's no 'fix' or bug there. We should encourage teams to adopt the newer and better practices. However, I don't think we want to appear to imply that older practices are "wrong" in any real sense.

@sharwell
Copy link
Member Author

I added the refactoring tag. Note that some items really are likely problem issues, such as a suggestion to change "paramName" to nameof(paramName) when throwing an ArgumentException or ArgumentNullException.

Others, such as changing a private readonly field with a property to a getter-only auto property, would be refactorings.

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

2 participants