Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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