static void AnalyzeSymbol(SymbolAnalysisContext context) { var overridable = RoslynInternals.GetOverridableMembers((INamedTypeSymbol)context.Symbol, context.CancellationToken); if (context.Compilation.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.Symbol.Locations.FirstOrDefault()); context.ReportDiagnostic(diagnostic); } }
async Task <Solution> OverrideAllMembersAsync(Document document, SyntaxNode type, CancellationToken cancellationToken) { var semanticModel = await document.GetSemanticModelAsync(cancellationToken); if (semanticModel == null) { return(document.Project.Solution); } 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); }