Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mayuki committed Oct 25, 2023
1 parent 6689b39 commit b3e8925
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Execute(GeneratorExecutionContext context)
if (classSymbol is null) continue;

var attrs = classSymbol.GetAttributes();
var attr = attrs.FirstOrDefault(x => x.AttributeClass?.Name == MagicOnionClientGenerationAttributeName);
var attr = attrs.FirstOrDefault(x => string.Equals(x.AttributeClass?.Name, MagicOnionClientGenerationAttributeName, StringComparison.Ordinal));
if (attr is null) return; // TODO: ReportDiagnostic

var options = ParseClientGenerationOptions(attr);
Expand All @@ -45,10 +45,12 @@ public void Execute(GeneratorExecutionContext context)

class SyntaxContextReceiver : ISyntaxContextReceiver
{
public List<(ClassDeclarationSyntax Node, SemanticModel SemanticModel)> Candidates { get; } = new();
public IReadOnlyList<(ClassDeclarationSyntax Node, SemanticModel SemanticModel)> Candidates { get; private set; } = Array.Empty<(ClassDeclarationSyntax Node, SemanticModel SemanticModel)>();

public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
{
List<(ClassDeclarationSyntax Node, SemanticModel SemanticModel)>? candidates = default;

if (context.Node is AttributeSyntax attrSyntax &&
attrSyntax.Parent is AttributeListSyntax &&
attrSyntax.Parent.Parent is ClassDeclarationSyntax classDeclSyntax)
Expand All @@ -57,15 +59,25 @@ attrSyntax.Parent is AttributeListSyntax &&
? qualifiedName.Right.Identifier.ValueText
: ((IdentifierNameSyntax)attrSyntax.Name).Identifier.ValueText;

if ((attrName.EndsWith("Attribute") && attrName == MagicOnionClientSourceGenerator.MagicOnionClientGenerationAttributeShortName) ||
(attrName == MagicOnionClientSourceGenerator.MagicOnionClientGenerationAttributeName))
if (attrName.StartsWith(MagicOnionClientSourceGenerator.MagicOnionClientGenerationAttributeShortName, StringComparison.Ordinal))
{
var attrSymbol = context.SemanticModel.GetSymbolInfo(attrSyntax).Symbol as IMethodSymbol;
if (attrSymbol is null) return;
if (string.Equals(attrName, MagicOnionClientSourceGenerator.MagicOnionClientGenerationAttributeShortName, StringComparison.Ordinal) ||
string.Equals(attrName, MagicOnionClientSourceGenerator.MagicOnionClientGenerationAttributeName, StringComparison.Ordinal))
{
var attrSymbol = context.SemanticModel.GetSymbolInfo(attrSyntax).Symbol as IMethodSymbol;
if (attrSymbol is null) return;

Candidates.Add((classDeclSyntax, context.SemanticModel));
candidates ??= new List<(ClassDeclarationSyntax Node, SemanticModel SemanticModel)>();

candidates.Add((classDeclSyntax, context.SemanticModel));
}
}
}

if (candidates is not null)
{
Candidates = candidates;
}
}
}

Expand Down

0 comments on commit b3e8925

Please sign in to comment.