Closed LWehmschulteAtRosenxt closed 4 months ago
Version Used: Microsoft.CodeAnalysis.CSharp" Version="4.9.2" Microsoft.CodeAnalysis.Analyzers" Version="3.3.4"
Steps to Reproduce:
// Dummy Class with Event partial class SomeClass { public event EventHandler? SomeEvent; }
// SourceGenerator private static void GetEvent(ITypeSymbol classSymbol) { classSymbol .GetAllMembers() .Where(x => x.Kind == SymbolKind.Event) .OfType<IEventSymbol>() .Where(x => x.DeclaredAccessibility == Accessibility.Public) .Where(x => !x.IsStatic) .ToList() .ForEach(evt => { var syntax = evt.DeclaringSyntaxReferences.First().GetSyntax(); // VariableDeclaratorSyntax }); }
Expected Behavior: The syntax variable should be of type EventVieldDeclaration
EventVieldDeclaration
Actual Behavior: See the syntax variable is of type VariableDeclaratorSyntax and not of type EventFieldDeclarationSyntax
VariableDeclaratorSyntax
EventFieldDeclarationSyntax
This is by design. Like fields, there can be multiple events declared in a single declaration. For example:
class C { event Action A, B; }
So the declaring syntax is the declarator.
Version Used: Microsoft.CodeAnalysis.CSharp" Version="4.9.2" Microsoft.CodeAnalysis.Analyzers" Version="3.3.4"
Steps to Reproduce:
Expected Behavior: The syntax variable should be of type
EventVieldDeclaration
Actual Behavior: See the syntax variable is of type
VariableDeclaratorSyntax
and not of typeEventFieldDeclarationSyntax