Quantcast
Channel: YouTrackReSharper (RSRP) - Bug and Issue Tracker
Viewing all articles
Browse latest Browse all 106942

RSRP-461581: Detect incorrect use of C# interpolated strings as format strings

$
0
0
Reporter Evgeny Morozov (shift_evgeny) Evgeny Morozov (shift_evgeny)
Created Nov 4, 2016 10:00:03 PM
Updated Apr 11, 2018 5:28:43 PM
Subsystem Code Analysis - C#
Assignee Andrey Dyatlov (Andrey.Dyatlov)
Priority Normal
State Fixed In Branch
Type Feature
Fix version No Fix versions
Affected versions 2016.2.2
Fixed In Version ReSharper Undefined
VsVersion All Versions
string.Format($"{0}", "my text")

The above code looks fine at first glance, but its return value is "0" - not "my text" as you might expect!

This can be hard for a human to see, but R# can probably detect this easily, since it already detects format strings. Using an interpolated string as a format strings should probably be a warning - it seems much more likely to be a mistake than intentional. (How often do you really need to "double-format" a string?)

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>