Skip to content

Commit ac02b66

Browse files
authored
Use symbol comparison in CustomMarshallerAttributeAnalyzer (#90850)
* Use symbol comparison in `CustomMarshallerAttributeAnalyzer` * Pass SymbolEqualityComparer
1 parent e811599 commit ac02b66

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,9 @@ public override void Initialize(AnalysisContext context)
618618

619619
private void PrepareForAnalysis(CompilationStartAnalysisContext context)
620620
{
621-
if (context.Compilation.GetBestTypeByMetadataName(TypeNames.CustomMarshallerAttribute) is not null)
621+
if (context.Compilation.GetBestTypeByMetadataName(TypeNames.CustomMarshallerAttribute) is { } customMarshallerAttribute)
622622
{
623-
var perCompilationAnalyzer = new PerCompilationAnalyzer(context.Compilation);
623+
var perCompilationAnalyzer = new PerCompilationAnalyzer(context.Compilation, customMarshallerAttribute);
624624
context.RegisterOperationAction(perCompilationAnalyzer.AnalyzeAttribute, OperationKind.Attribute);
625625
}
626626
}
@@ -630,18 +630,20 @@ private sealed partial class PerCompilationAnalyzer
630630
private readonly Compilation _compilation;
631631
private readonly INamedTypeSymbol _spanOfT;
632632
private readonly INamedTypeSymbol _readOnlySpanOfT;
633+
private readonly INamedTypeSymbol _customMarshallerAttribute;
633634

634-
public PerCompilationAnalyzer(Compilation compilation)
635+
public PerCompilationAnalyzer(Compilation compilation, INamedTypeSymbol customMarshallerAttribute)
635636
{
636637
_compilation = compilation;
638+
_customMarshallerAttribute = customMarshallerAttribute;
637639
_spanOfT = compilation.GetBestTypeByMetadataName(TypeNames.System_Span_Metadata);
638640
_readOnlySpanOfT = compilation.GetBestTypeByMetadataName(TypeNames.System_ReadOnlySpan_Metadata);
639641
}
640642
public void AnalyzeAttribute(OperationAnalysisContext context)
641643
{
642644
IAttributeOperation attr = (IAttributeOperation)context.Operation;
643645
if (attr.Operation is IObjectCreationOperation attrCreation
644-
&& attrCreation.Type.ToDisplayString() == TypeNames.CustomMarshallerAttribute)
646+
&& attrCreation.Type.Equals(_customMarshallerAttribute, SymbolEqualityComparer.Default))
645647
{
646648
INamedTypeSymbol entryType = (INamedTypeSymbol)context.ContainingSymbol!;
647649
IArgumentOperation? managedTypeArgument = attrCreation.GetArgumentByOrdinal(0);

0 commit comments

Comments
 (0)