static void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context) { var symbol = context.Compilation.GetSemanticModel(context.Node.SyntaxTree).GetDeclaredSymbol(context.Node) as INamedTypeSymbol; if (symbol == null) { return; } var overridable = RoslynInternals.GetOverridableMembers(symbol, context.CancellationToken); if (context.Node.Language == LanguageNames.VisualBasic) { overridable = overridable.Where(x => x.MetadataName != WellKnownMemberNames.DestructorName) // VB doesn't support overriding events (yet). See https://github.com/dotnet/vblang/issues/63 .Where(x => x.Kind != SymbolKind.Event) .ToImmutableArray(); } if (overridable.Length != 0) { var diagnostic = Diagnostic.Create(Rule, context.Node.GetLocation()); context.ReportDiagnostic(diagnostic); } }
async Task <Solution> OverrideAllMembersAsync(Document document, SyntaxNode type, CancellationToken cancellationToken) { var semanticModel = await document.GetSemanticModelAsync(cancellationToken); var symbol = semanticModel.GetDeclaredSymbol(type) as INamedTypeSymbol; if (symbol == null) { return(document.Project.Solution); } var overridables = RoslynInternals.GetOverridableMembers(symbol, cancellationToken); if (type.Language == LanguageNames.VisualBasic) { overridables = overridables .Where(x => x.MetadataName != WellKnownMemberNames.DestructorName) // VB doesn't support overriding events (yet). See https://github.com/dotnet/vblang/issues/63 .Where(x => x.Kind != SymbolKind.Event) .ToImmutableArray(); } var generator = SyntaxGenerator.GetGenerator(document); var memberTasks = overridables.Select( m => RoslynInternals.OverrideAsync(generator, m, symbol, document, cancellationToken: cancellationToken)); var members = await Task.WhenAll(memberTasks); var newDoc = await RoslynInternals.AddMemberDeclarationsAsync(document.Project.Solution, symbol, members, cancellationToken); return(newDoc.Project.Solution); }