Make Visual Studio suggest explicit type instead of var when ToList is called
This suggestion is migrated to Developer Community. Please use below link to view the current status.
Currently when the .editorconfig or the Visual Studio settings say that the code should prefer var when the type is apparent Visual Studio suggest that I change code like this
List<string> test = Enumerable.Range(1, 2).Select(i => i.ToString()).ToList();
I should use var because the type is apparent. It does this even when I have code like GetItems().ToList(); While calling ToList makes it apparent that the type is a List<T> it is not the List that I care about, it is the T. This is a clearly a case where if the type should be explicit (assuming the user set csharp_style_var_when_type_is_apparent = true). Please provide a fix to this behavior. In addition code like this
MessageProcessorBase messageProcessor = MessageProcessorBase.GetMessageProcessor(eventType);
Now triggers a suggestion to use var. While the type is indeed mentioned on the right I am calling a static method and it may have returned something else.
Please change this behavior or provide additional option for this corner cases so users can configure them as they see fit.
Victor Kallai commented
I can't vote on this, so I will give it a +1.