Skip to content

Commit

Permalink
Use symbol comparison in CustomMarshallerAttributeAnalyzer (#90850)
Browse files Browse the repository at this point in the history
* Use symbol comparison in `CustomMarshallerAttributeAnalyzer`

* Pass SymbolEqualityComparer
  • Loading branch information
Youssef1313 authored Aug 19, 2023
1 parent e811599 commit ac02b66
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,9 @@ public override void Initialize(AnalysisContext context)

private void PrepareForAnalysis(CompilationStartAnalysisContext context)
{
if (context.Compilation.GetBestTypeByMetadataName(TypeNames.CustomMarshallerAttribute) is not null)
if (context.Compilation.GetBestTypeByMetadataName(TypeNames.CustomMarshallerAttribute) is { } customMarshallerAttribute)
{
var perCompilationAnalyzer = new PerCompilationAnalyzer(context.Compilation);
var perCompilationAnalyzer = new PerCompilationAnalyzer(context.Compilation, customMarshallerAttribute);
context.RegisterOperationAction(perCompilationAnalyzer.AnalyzeAttribute, OperationKind.Attribute);
}
}
Expand All @@ -630,18 +630,20 @@ private sealed partial class PerCompilationAnalyzer
private readonly Compilation _compilation;
private readonly INamedTypeSymbol _spanOfT;
private readonly INamedTypeSymbol _readOnlySpanOfT;
private readonly INamedTypeSymbol _customMarshallerAttribute;

public PerCompilationAnalyzer(Compilation compilation)
public PerCompilationAnalyzer(Compilation compilation, INamedTypeSymbol customMarshallerAttribute)
{
_compilation = compilation;
_customMarshallerAttribute = customMarshallerAttribute;
_spanOfT = compilation.GetBestTypeByMetadataName(TypeNames.System_Span_Metadata);
_readOnlySpanOfT = compilation.GetBestTypeByMetadataName(TypeNames.System_ReadOnlySpan_Metadata);
}
public void AnalyzeAttribute(OperationAnalysisContext context)
{
IAttributeOperation attr = (IAttributeOperation)context.Operation;
if (attr.Operation is IObjectCreationOperation attrCreation
&& attrCreation.Type.ToDisplayString() == TypeNames.CustomMarshallerAttribute)
&& attrCreation.Type.Equals(_customMarshallerAttribute, SymbolEqualityComparer.Default))
{
INamedTypeSymbol entryType = (INamedTypeSymbol)context.ContainingSymbol!;
IArgumentOperation? managedTypeArgument = attrCreation.GetArgumentByOrdinal(0);
Expand Down

0 comments on commit ac02b66

Please sign in to comment.