Skip to content
| Marketplace
Sign in
Visual Studio>Tools>PreserveFormattableStringForObjParams
PreserveFormattableStringForObjParams

PreserveFormattableStringForObjParams

Koshelew

|
119 installs
| (0) | Free
Diagnostics extension: when interpolated string ($"...") is used as an object, will force it to be cast to FormattableString (this will preserve raw data values and is very useful, for example, when unit testing log messages).
Download

Diagnostics Extension: when interpolated string ($"...") is used as an object, will force it to be cast to FormattableString (this will preserve raw data values and is very useful, for example, when unit testing log messages).

If you don't know about .NET 4.6 type 'FormattableString' - make sure to read a short article: http://ikoshelev.azurewebsites.net/search/id/9/-Advanced-usage-of-interpolated-strings-in-CSharp

This analyzer will make sure, that raw values of interpolated string will not be lost due to cast to an object, but will instead be preserved by casting it to FormattableString.

 

Before:

public void Bar()          
{ 
     // Compiler will give you an error 
     Foo($"abc{1}", obj2 : $"abc{2}"); 
} 
 
public void Foo(object obj, object obj2) 
{ 
}

 

After fix application:

public void Bar()
{
      Foo((FormattableString)$"abc{1}", obj2 : (FormattableString)$"abc{2}");
}
public void Foo(object obj, object obj2)
{
      // arguments of both strings can be examined
}

 
 
 
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft