Skip to content

Commit a9feab1

Browse files
committed
More straightforward namespace search
1 parent 6fc1b49 commit a9feab1

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

sdk/eventgrid/Azure.Messaging.EventGrid/EventGridSourceGenerator/src/EventGridSourceGenerator.cs

+5-22
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
3737
transform: static (ctx, cancellationToken) =>
3838
{
3939
var semanticModel = ctx.SemanticModel;
40-
var classDecl = (ClassDeclarationSyntax)ctx.Node;
41-
42-
// Get the symbol for the class declaration
43-
var symbol = semanticModel.GetDeclaredSymbol(classDecl, cancellationToken);
44-
if (symbol == null)
45-
{
46-
return null;
47-
}
48-
49-
// Check if the symbol is in the SystemEvents namespace
50-
var containingNamespace = symbol.ContainingNamespace;
51-
while (containingNamespace != null)
52-
{
53-
if (containingNamespace.Name == "SystemEvents")
54-
{
55-
return classDecl;
56-
}
57-
containingNamespace = containingNamespace.ContainingNamespace;
58-
}
59-
60-
// Not in the SystemEvents namespace
61-
return null;
40+
var classDeclaration = (ClassDeclarationSyntax)ctx.Node;
41+
42+
var declaredSymbol = semanticModel.GetDeclaredSymbol(classDeclaration, cancellationToken);
43+
44+
return declaredSymbol?.ContainingNamespace is { Name: "SystemEvents" } ? classDeclaration : null;
6245
})
6346
.Where(static cls => cls != null);
6447

0 commit comments

Comments
 (0)