4

For Resharper we can selectively turn it on/off, but I could not find a way to turn off the built-in Visual Studio 2015 code highlights/suggestions.

The reason I want to do this is because I have quite a few left-join linqs and these queries messed up Visual Studio.

I am seeing lots of squiggles on my linqs and I prefer to turn them off.

Here is one of the error I am talking about.. I have no idea how to get rid of it.

The result of the expression is always 'true' since a value of type 'int' is never equal to 'null' of type 'int?'

The result of the expression is always 'true' since a value of type 'int' is never equal to 'null' of type 'int?'

EDIT

I have found a way to fix this from ScottGu's blog here: The C# ?? null coalescing operator (and using it with LINQ)

Rosdi Kasim
  • 24,267
  • 23
  • 130
  • 154
  • Do you mean IntelliSense or Syntax highlighting? – TylerH Jul 11 '15 at 03:46
  • I mean the live red, yellow, green squiggles that highlights errors in the code. – Rosdi Kasim Jul 11 '15 at 03:58
  • @RosdiKasim: Use the lightbulb to add a `#pragma` to disable the warning. – SLaks Jul 12 '15 at 17:36
  • It looks like the hint is actually right in this case. The property Id will always have a value here. Actual correct thing to check IsSelected in this case would be IsSelected = ps.Any() – mlehmk Apr 07 '17 at 17:57

2 Answers2

8

If you are talking about the Code Analysis rules. Then under the project references, there is an analyzers node.

Visual Studio Analyzers Node

If you right click and select "Open Active Rule Set", then you can turn off any of the analyzers you don't want.

John Koerner
  • 37,428
  • 8
  • 84
  • 134
  • I think this is it, but I still could not find the one that relates to my scenario. Btw I have found a way to fix this from ScottGu's blog: http://weblogs.asp.net/scottgu/the-new-c-null-coalescing-operator-and-using-it-with-linq – Rosdi Kasim Jul 12 '15 at 03:21
  • @RosdiKasim it would have been useful if you had posted the correct link or an answer to your own question that describes how you solved your problem – thumbmunkeys Aug 05 '15 at 08:55
  • 1
    Is there any way to store all personal Code Analysis rules changes in "This computer" scope rather than in solution folder? Just like ReSharper offers this possibility for its settings. – Sam Apr 18 '16 at 10:32
  • Not available anymore in .Net Core libraries. – Maxim Jul 16 '16 at 00:53
0

Have you tried ((int?)result.Id).HasValue? This is the correct way to check a nullable type for nul value.

FelixSFD
  • 6,052
  • 10
  • 43
  • 117
Wietze
  • 313
  • 5
  • 8