File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -532,6 +532,12 @@ attribute.AttributeClass is INamedTypeSymbol nt &&
532
532
return isInline ;
533
533
}
534
534
535
+ /// <summary>
536
+ /// Returns true if this type implements `System.IFormattable`.
537
+ /// </summary>
538
+ public static bool ImplementsIFormattable ( this ITypeSymbol type ) =>
539
+ type . AllInterfaces . Any ( i => i . Name == "IFormattable" && i . ContainingNamespace . ToString ( ) == "System" ) ;
540
+
535
541
/// <summary>
536
542
/// Holds if this type is of the form <code>System.ReadOnlySpan<byte></code>.
537
543
/// </summary>
Original file line number Diff line number Diff line change 1
1
using System . IO ;
2
+ using Microsoft . CodeAnalysis ;
2
3
using Microsoft . CodeAnalysis . CSharp ;
3
4
using Microsoft . CodeAnalysis . CSharp . Syntax ;
4
5
using Semmle . Extraction . Kinds ;
@@ -20,7 +21,15 @@ protected override void PopulateExpression(TextWriter trapFile)
20
21
{
21
22
case SyntaxKind . Interpolation :
22
23
var interpolation = ( InterpolationSyntax ) c ;
23
- ImplicitToString . Create ( Context , interpolation . Expression , this , child ++ ) ;
24
+ var exp = interpolation . Expression ;
25
+ if ( Context . GetTypeInfo ( exp ) . Type is ITypeSymbol type && ! type . ImplementsIFormattable ( ) )
26
+ {
27
+ ImplicitToString . Create ( Context , exp , this , child ++ ) ;
28
+ }
29
+ else
30
+ {
31
+ Create ( Context , exp , this , child ++ ) ;
32
+ }
24
33
break ;
25
34
case SyntaxKind . InterpolatedStringText :
26
35
// Create a string literal
You can’t perform that action at this time.
0 commit comments