Currently resharper is generating ToString in C# using the string interpolation (i.e. $"Member: {Member}"
).
Is it possible to modify it so it will use string.Format
instead (i.e. string.Format("Member: {0}",Member))
Currently resharper is generating ToString in C# using the string interpolation (i.e. $"Member: {Member}"
).
Is it possible to modify it so it will use string.Format
instead (i.e. string.Format("Member: {0}",Member))
ReSharper > Options > Code Inspection + Inspection Severity > C# > "Language Usage Opportunities" > "Use string interpolation expression". Change this to "Do not show".
I just stumbled over the same problem in Resharper 2016.1
For me it helped to position the caret over the +
operator in a string concatenation and hit Alt+Enter
. It then lists an option to refactor to string.Format. Positioning the caret over the string does not work. The option will not be available in that case.
This must be a recent change because I use that refactoring often for localization reasons.
It might be worth checking out Fody.ToString project, it can automatically create an overload of your ToString method after build using IL Weaving:
Your Code:
[ToString]
class TestClass
{
public int Foo { get; set; }
public double Bar { get; set; }
[IgnoreDuringToString]
public string Baz { get; set; }
}
Gets converted to:
class TestClass
{
public int Foo { get; set; }
public double Bar { get; set; }
public string Baz { get; set; }
public override string ToString()
{
return string.Format(
CultureInfo.InvariantCulture,
"{{T: TestClass, Foo: {0}, Bar: {1}}}",
this.Foo,
this.Bar);
}
}
Check it out, right time saver - https://github.com/Fody/ToString