DotNetAnalyzers / NullParameterCheckRefactoring

Null Parameter Check Refactoring for Reference Type Parameters
MIT License
14 stars 4 forks source link

Only use nameof() for ToolsVersion > 14 #1

Closed sharwell closed 9 years ago

sharwell commented 9 years ago

To improve the ability of this code fix to preserve compatibility with older versions of Visual Studio, it should only use the nameof operator in cases where the project specifies Visual Studio 2015 (or newer) as the preferred compiler. The easiest way to detect this is with the ToolsVersion attribute of the project file.

Here is an example where ToolsVersion is set to 14:

https://github.com/DotNetAnalyzers/DefaultValueDiagnostic/blob/master/DefaultParameterDiagnostic/DefaultParameterDiagnostic/DefaultParameterDiagnostic.csproj#L2

Here is an example where the ToolsVersion is set to 4:

https://github.com/openstacknetsdk/openstack.net/blob/master/src/corelib/corelib.v3.5.csproj#L2

In the latter case, compatibility going back to Visual Studio 2010 is important for the project, but it would still be useful to have access to this code fix.

tugberkugurlu commented 9 years ago

@sharwell I guess we cannot check ToolsVersion diagrammatically, correct? In that case, should we produce separate VSIXs?

Even if the ToolsVersion is 14, can I use nameof operator in any version of C#/.NET?