public static async Task <Document> ApplyVisitors(Document document, ICodeAnalysisServices services, CancellationToken cancellationToken) { #if DEBUG if (Debugger.IsAttached) { cancellationToken = CancellationToken.None; } #endif var language = document.Project.Language; var prepares = services.GetLanguageServices <IDocumentVisitor>(language, DocumentVisitorLayer.Prepare).ToArray(); foreach (var prepare in prepares) { document = await prepare.VisitAsync(document, cancellationToken); } var scaffolds = services.GetLanguageServices <IDocumentVisitor>(language, DocumentVisitorLayer.Scaffold).ToArray(); foreach (var scaffold in scaffolds) { document = await scaffold.VisitAsync(document, cancellationToken); } var rewriters = services.GetLanguageServices <IDocumentVisitor>(language, DocumentVisitorLayer.Rewrite).ToArray(); foreach (var rewriter in rewriters) { document = await rewriter.VisitAsync(document, cancellationToken); } var fixups = services.GetLanguageServices <IDocumentVisitor>(language, DocumentVisitorLayer.Fixup).ToArray(); foreach (var fixup in fixups) { document = await fixup.VisitAsync(document, cancellationToken); } return(document); }
/// <summary> /// Gets the first (or none) language service of the given type that matches the parameters. /// See <see cref="ICodeAnalysisServices.GetLanguageServices{TService}(string, string)"/>. /// </summary> /// <typeparam name="TService">The language service type, which should match the <see cref="ExportLanguageServiceAttribute.ServiceType"/> registration attribute.</typeparam> public static TService GetLanguageService <TService>(this ICodeAnalysisServices services, string language, string layer = ServiceLayer.Default) where TService : ILanguageService => services.GetLanguageServices <TService>(language, layer).FirstOrDefault();
/// <summary> /// Gets the first (or none) language service that matches the given parameters. /// See <see cref="ICodeAnalysisServices.GetLanguageServices(string, string, string)"/>. /// </summary> public static ILanguageService GetLanguageService(this ICodeAnalysisServices services, string language, string serviceType, string layer = ServiceLayer.Default) => services.GetLanguageServices(language, serviceType, layer).FirstOrDefault();