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 &&
532532 return isInline ;
533533 }
534534
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+
535541 /// <summary>
536542 /// Holds if this type is of the form <code>System.ReadOnlySpan<byte></code>.
537543 /// </summary>
Original file line number Diff line number Diff line change 11using System . IO ;
2+ using Microsoft . CodeAnalysis ;
23using Microsoft . CodeAnalysis . CSharp ;
34using Microsoft . CodeAnalysis . CSharp . Syntax ;
45using Semmle . Extraction . Kinds ;
@@ -20,7 +21,15 @@ protected override void PopulateExpression(TextWriter trapFile)
2021 {
2122 case SyntaxKind . Interpolation :
2223 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+ }
2433 break ;
2534 case SyntaxKind . InterpolatedStringText :
2635 // Create a string literal
You can’t perform that action at this time.
0 commit comments