C#: Do not insert a synthetic ToString call in interpolation expressions, if the type implements IFormattable.

This commit is contained in:
Michael Nebel
2025-01-14 15:57:21 +01:00
parent ab70a945e4
commit 6a406b28d1
2 changed files with 16 additions and 1 deletions

View File

@@ -532,6 +532,12 @@ namespace Semmle.Extraction.CSharp
return isInline;
}
/// <summary>
/// Returns true if this type implements `System.IFormattable`.
/// </summary>
public static bool ImplementsIFormattable(this ITypeSymbol type) =>
type.AllInterfaces.Any(i => i.Name == "IFormattable" && i.ContainingNamespace.ToString() == "System");
/// <summary>
/// Holds if this type is of the form <code>System.ReadOnlySpan&lt;byte&gt;</code>.
/// </summary>