• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CodeAnalysis.Solution类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.CodeAnalysis.Solution的典型用法代码示例。如果您正苦于以下问题:C# Solution类的具体用法?C# Solution怎么用?C# Solution使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Solution类属于Microsoft.CodeAnalysis命名空间,在下文中一共展示了Solution类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: PreviewChanges

 public Solution PreviewChanges(
     string title,
     string helpString,
     string description,
     string topLevelName,
     Glyph topLevelGlyph,
     Solution newSolution,
     Solution oldSolution,
     bool showCheckBoxes = true)
 {
     var engine = new PreviewEngine(
         title,
         helpString,
         description,
         topLevelName,
         topLevelGlyph,
         newSolution,
         oldSolution,
         _componentModel,
         _imageService,
         showCheckBoxes);
     _previewChanges.PreviewChanges(engine);
     engine.CloseWorkspace();
     return engine.FinalSolution;
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:25,代码来源:PreviewService.cs


示例2: RaiseWorkspaceChangedEventAsync

        protected Task RaiseWorkspaceChangedEventAsync(WorkspaceChangeKind kind, Solution oldSolution, Solution newSolution, ProjectId projectId = null, DocumentId documentId = null)
        {
            if (newSolution == null)
            {
                throw new ArgumentNullException("newSolution");
            }

            if (oldSolution == newSolution)
            {
                return SpecializedTasks.EmptyTask;
            }

            if (projectId == null && documentId != null)
            {
                projectId = documentId.ProjectId;
            }

            var handlers = this.eventMap.GetEventHandlers<EventHandler<WorkspaceChangeEventArgs>>(WorkspaceChangeEventName);
            if (handlers.Length > 0)
            {
                return this.ScheduleTask(() =>
                {
                    var args = new WorkspaceChangeEventArgs(kind, oldSolution, newSolution, projectId, documentId);
                    foreach (var handler in handlers)
                    {
                        handler(this, args);
                    }
                }, "Workspace.WorkspaceChanged");
            }
            else
            {
                return SpecializedTasks.EmptyTask;
            }
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:34,代码来源:Workspace_Events.cs


示例3: LoadInitialSemanticVersions

 public void LoadInitialSemanticVersions(Solution solution)
 {
     foreach (var project in solution.Projects)
     {
         LoadInitialSemanticVersions(project);
     }
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:7,代码来源:SemanticVersionTrackingService.cs


示例4: SolutionGenerator

        public SolutionGenerator(
            string projectFilePath,
            string commandLineArguments,
            string outputAssemblyPath,
            string solutionSourceFolder,
            string solutionDestinationFolder,
            string serverPath,
            string networkShare)
        {
            this.ProjectFilePath = projectFilePath;
            string projectName = Path.GetFileNameWithoutExtension(projectFilePath);
            string language = projectFilePath.EndsWith(".vbproj", StringComparison.OrdinalIgnoreCase) ?
                LanguageNames.VisualBasic : LanguageNames.CSharp;
            this.SolutionSourceFolder = solutionSourceFolder;
            this.SolutionDestinationFolder = solutionDestinationFolder;
            this.ServerPath = serverPath;
            this.NetworkShare = networkShare;
            string projectSourceFolder = Path.GetDirectoryName(projectFilePath);

            this.solution = CreateSolution(
                commandLineArguments,
                projectName,
                language,
                projectSourceFolder,
                outputAssemblyPath);
        }
开发者ID:akrisiun,项目名称:SourceBrowser,代码行数:26,代码来源:SolutionGenerator.cs


示例5: GetGraphAsync

        public async Task<GraphBuilder> GetGraphAsync(Solution solution, IGraphContext context, CancellationToken cancellationToken)
        {
            var graphBuilder = await GraphBuilder.CreateForInputNodesAsync(solution, context.InputNodes, cancellationToken).ConfigureAwait(false);

            foreach (var node in context.InputNodes)
            {
                var symbol = graphBuilder.GetSymbol(node);
                var references = await SymbolFinder.FindReferencesAsync(symbol, solution, cancellationToken).ConfigureAwait(false);

                foreach (var reference in references)
                {
                    var referencedSymbol = reference.Definition;
                    var projectId = graphBuilder.GetContextProject(node).Id;

                    var allLocations = referencedSymbol.Locations.Concat(reference.Locations.Select(r => r.Location))
                                                                 .Where(l => l != null && l.IsInSource);

                    foreach (var location in allLocations)
                    {
                        var locationNode = GetLocationNode(referencedSymbol, location, context, projectId, cancellationToken);
                        graphBuilder.AddLink(node, CodeLinkCategories.SourceReferences, locationNode);
                    }
                }
            }

            return graphBuilder;
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:27,代码来源:IsUsedByGraphQuery.cs


示例6: TestListCategorizer

 public TestListCategorizer(string pathToVsmdiFile, string pathToSolution)
 {
     _workspace = MSBuildWorkspace.Create();
     _solution = _workspace.OpenSolutionAsync(pathToSolution).Result;
     var vsmdiParser = new VsmdiParser();
     _testlists = vsmdiParser.ReadFile(pathToVsmdiFile);
 }
开发者ID:bremnes,项目名称:TagUnitTestFromTestlist,代码行数:7,代码来源:TestListCategorizer.cs


示例7: AnalyzeCoupling

        // TODO Refactor
        private IEnumerable<ClassCouplingMetrics> AnalyzeCoupling(Solution solution)
        {
            var documents = _documentWalker.GetAllDocumentsFromSolution(solution);
            foreach (var document in documents)
            {
                var typeDeclarations = _documentWalker.GetNodesFromDocument<TypeDeclarationSyntax>(document);
                var semanticModel = document.GetSemanticModelAsync().Result;

                foreach (var type in typeDeclarations)
                {
                    var classCouplingMetrics = new ClassCouplingMetrics(type.Identifier.Text);
                    var invocations = type.DescendantNodes().OfType<InvocationExpressionSyntax>();
                    foreach (var invocation in invocations)
                    {
                        classCouplingMetrics.TotalAmountCalls ++;
                        string nameSpace;
                        if (IsInternal(invocation, semanticModel, out nameSpace))
                        {
                            classCouplingMetrics.TotalInternCalls++;
                        }
                        else
                        {
                            classCouplingMetrics.TotalExternCalls++;
                            classCouplingMetrics.AddExternCall(nameSpace);
                        }
                    }
                    yield return classCouplingMetrics;
                }
            }
        }
开发者ID:birksimon,项目名称:CodeAnalysis,代码行数:31,代码来源:CouplingInspector.cs


示例8: FindMethodSymbolAndProjectInSolution

 public static ProjectMethod FindMethodSymbolAndProjectInSolution(Solution solution, MethodDescriptor methodDescriptor)
 {
     ProjectMethod res;
     res.Method = null;
     res.Project = null;
     foreach (var project in solution.Projects)
     {
         // Alternative method using SymbolFinder, it only works with methods in the solution
         // Discarded by the moment
         //var methodDeclarations = SymbolFinder.FindDeclarationsAsync(project, methodDescriptor.MethodName,false).Result;
         //methodDeclarations = methodDeclarations.Where(ms => methodDescriptor.SameAsMethodSymbom(ms as IMethodSymbol));
         //if (methodDeclarations.Count() > 0)
         //{
         //    return methodDeclarations.First() as IMethodSymbol;
         //}
         //else
         //{
         // My own method
         var method = FindMethodSymbolInProject(methodDescriptor, project);
         if (method != null)
         {
             res.Project = project;
             res.Method = method;
             return res;
         }
         //}
     }
     return res;
 }
开发者ID:TubaKayaDev,项目名称:Call-Graph-Builder-DotNet,代码行数:29,代码来源:RoslynSymbolFactory.cs


示例9: AnalyseSolutionAsync

        private async Task<List<ProjectAnalysisResult>> AnalyseSolutionAsync(Solution solution, ImmutableArray<DiagnosticAnalyzer> analyzers, Configuration configuration)
        {
            var ruleIds = analyzers
                .SelectMany(a => a.SupportedDiagnostics.Select(d => d.Id))
                .Where(d => !_configuration.DisabledDiagnostics.Contains(d))
                .ToImmutableHashSet();

            var projectAnalysisTasks = solution.Projects
                // First, Running analysis
                .Select(p => new { Project = p, Task = AnalyzeProjectAsync(p, analyzers) })
                .ToList()
                // Then we need to print all the results
                .Select(p => new { Project = p.Project, Task = p.Task.ContinueWith(t =>
                    {
                        var diagnostics = t.Result.Where(d => ruleIds.Contains(d.Id)).ToImmutableArray();
                        if (configuration.RunInfoLevelDiagnostics)
                        {
                            diagnostics = diagnostics.Where(d => d.Severity != DiagnosticSeverity.Info).ToImmutableArray();
                        }
                        LogDiagnostics(p.Project, diagnostics);

                        return t;
                    }).Unwrap()})
                .ToList();

            // And need to wait when all the analysis and printing tasks would be finished
            await Task.WhenAll(projectAnalysisTasks.Select(p => p.Task));

            // And only after now we can build the result
            var result =
                projectAnalysisTasks
                .Select(r => new ProjectAnalysisResult(r.Project, r.Task.Result.Where(d => ruleIds.Contains(d.Id)).ToImmutableArray())).ToList();

            return result;
        }
开发者ID:SergeyTeplyakov,项目名称:ErrorProne.NET,代码行数:35,代码来源:AnalyzerRunner.cs


示例10: SolutionAnalayzer

 public SolutionAnalayzer(string solutionPath)
 {
     _workspace = MSBuildWorkspace.Create();
     _workspace.WorkspaceFailed += _workspace_WorkspaceFailed;
     _solution = _workspace.OpenSolutionAsync(solutionPath).Result;
     _refsourceLinkProvider.Init();
 }
开发者ID:george2giga,项目名称:SourceBrowser,代码行数:7,代码来源:SolutionAnalyzer.cs


示例11: DisplayReferencedSymbols

 public override void DisplayReferencedSymbols(Solution solution, IEnumerable<ReferencedSymbol> referencedSymbols)
 {
     foreach (var presenter in _referencedSymbolsPresenters)
     {
         presenter.Value.DisplayResult(solution, referencedSymbols);
     }
 }
开发者ID:xyh413,项目名称:roslyn,代码行数:7,代码来源:RoslynVisualStudioWorkspace.cs


示例12: MemberTarget

 public MemberTarget(SourceTextContainer textContainer, ISymbol memberIdentifier, Project project, Solution solution)
 {
     _textContainer = textContainer;
     _memberIdentifier = memberIdentifier;
     _project = project;
     _solution = solution;
 }
开发者ID:AlexEyler,项目名称:InheritanceMargin,代码行数:7,代码来源:RoslynMemberTarget.cs


示例13: RenameFields

            private async Task<Solution> RenameFields(Solution solution, DocumentId documentId, int count, CancellationToken cancellationToken)
            {
                Solution oldSolution = null;
                for (int i = 0; i < count; i++)
                {
                    oldSolution = solution;

                    var semanticModel = await solution.GetDocument(documentId).GetSemanticModelAsync(cancellationToken);
                    var root = await semanticModel.SyntaxTree.GetRootAsync(cancellationToken);
                    var declaration = root.GetAnnotatedNodes(s_markerAnnotation).ElementAt(i);

                    // Make note, VB represents "fields" marked as "WithEvents" as properties, so don't be
                    // tempted to treat this as a IFieldSymbol. We only need the name, so ISymbol is enough.
                    var fieldSymbol = semanticModel.GetDeclaredSymbol(declaration, cancellationToken);
                    var newName = GetNewFieldName(fieldSymbol);

                    // Can happen with pathologically bad field names like _
                    if (newName == fieldSymbol.Name)
                    {
                        continue;
                    }

                    solution = await Renamer.RenameSymbolAsync(solution, fieldSymbol, newName, solution.Workspace.Options, cancellationToken).ConfigureAwait(false);
                    solution = await CleanSolutionAsync(solution, oldSolution, cancellationToken);
                }

                return solution;
            }
开发者ID:patricksadowski,项目名称:codeformatter,代码行数:28,代码来源:PrivateFieldNamingRule.cs


示例14: CreateAsync

        internal static async Task<ImmutableList<CodeFixEquivalenceGroup>> CreateAsync(CodeFixProvider codeFixProvider, IEnumerable<Diagnostic> allDiagnostics, Solution solution)
        {
            var fixAllProvider = codeFixProvider.GetFixAllProvider();

            var relevantDiagnostics = allDiagnostics.Where(diagnostic => codeFixProvider.FixableDiagnosticIds.Contains(diagnostic.Id)).ToImmutableArray();

            if (fixAllProvider == null)
            {
                return ImmutableList.Create<CodeFixEquivalenceGroup>();
            }

            List<CodeAction> actions = new List<CodeAction>();

            foreach (var diagnostic in relevantDiagnostics)
            {
                actions.AddRange(await GetFixesAsync(solution, codeFixProvider, diagnostic).ConfigureAwait(false));
            }

            List<CodeFixEquivalenceGroup> groups = new List<CodeFixEquivalenceGroup>();

            foreach (var item in actions.GroupBy(x => x.EquivalenceKey))
            {
                groups.Add(new CodeFixEquivalenceGroup(item.Key, solution, fixAllProvider, codeFixProvider, relevantDiagnostics));
            }

            return groups.ToImmutableList();
        }
开发者ID:robinsedlaczek,项目名称:StyleCopAnalyzers,代码行数:27,代码来源:CodeFixEquivalenceGroup.cs


示例15: FindDerivedInterfacesAsync

 public static Task<IEnumerable<INamedTypeSymbol>> FindDerivedInterfacesAsync(
     this INamedTypeSymbol type,
     Solution solution,
     CancellationToken cancellationToken)
 {
     return FindDerivedInterfacesAsync(type, solution, null, cancellationToken);
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:7,代码来源:INamedTypeSymbolExtensions.cs


示例16: RunAsync

        public static Task<ImmutableArray<PatternSearchResult>> RunAsync(Solution solution, ImmutableArray<PatternSearch> searches)
        {
            if (solution == null)
                throw new ArgumentNullException(nameof(solution));

            return RunAsync(solution.Projects, searches);
        }
开发者ID:terrajobst,项目名称:apiporter,代码行数:7,代码来源:PatternSearch.RunAsync.cs


示例17: RaiseWorkspaceChangedEventAsync

        protected Task RaiseWorkspaceChangedEventAsync(WorkspaceChangeKind kind, Solution oldSolution, Solution newSolution, ProjectId projectId = null, DocumentId documentId = null)
        {
            if (newSolution == null)
            {
                throw new ArgumentNullException(nameof(newSolution));
            }

            if (oldSolution == newSolution)
            {
                return SpecializedTasks.EmptyTask;
            }

            if (projectId == null && documentId != null)
            {
                projectId = documentId.ProjectId;
            }

            var ev = _eventMap.GetEventHandlers<EventHandler<WorkspaceChangeEventArgs>>(WorkspaceChangeEventName);
            if (ev.HasHandlers)
            {
                return this.ScheduleTask(() =>
                {
                    var args = new WorkspaceChangeEventArgs(kind, oldSolution, newSolution, projectId, documentId);
                    ev.RaiseEvent(handler => handler(this, args));
                }, "Workspace.WorkspaceChanged");
            }
            else
            {
                return SpecializedTasks.EmptyTask;
            }
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:31,代码来源:Workspace_Events.cs


示例18: TryGetReference

        internal static bool TryGetReference(
            Solution solution, ProjectReference projectReference, Compilation finalOrDeclarationCompilation, VersionStamp version, out MetadataReference reference)
        {
            // if we have one from snapshot cache, use it. it will make sure same compilation will get same metadata reference always.
            MetadataOnlyReferenceSet referenceSet;
            if (s_snapshotCache.TryGetValue(finalOrDeclarationCompilation, out referenceSet))
            {
                reference = referenceSet.GetMetadataReference(finalOrDeclarationCompilation, projectReference.Aliases, projectReference.EmbedInteropTypes);
                return true;
            }

            // okay, now use version based cache that can live multiple compilation as long as there is no semantic changes.

            // get one for the branch
            if (TryGetReferenceFromBranch(solution.BranchId, projectReference, finalOrDeclarationCompilation, version, out reference))
            {
                return true;
            }

            // see whether we can use primary branch one
            var primaryBranchId = solution.Workspace.PrimaryBranchId;
            if (solution.BranchId != primaryBranchId &&
                TryGetReferenceFromBranch(primaryBranchId, projectReference, finalOrDeclarationCompilation, version, out reference))
            {
                return true;
            }

            // noop, we don't have any
            reference = null;
            return false;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:31,代码来源:MetadataOnlyReference.cs


示例19: EvaluateImpl

		protected override Task<EvaluationResult> EvaluateImpl(SyntaxNode node, SemanticModel semanticModel, Solution solution)
		{
			//// TODO: For this to be correct, we need flow analysis to determine if a given method
			//// is actually invoked inside the current constructor. A method may be assigned to a
			//// delegate which can be called inside or outside the constructor. A method may also
			//// be called from within a lambda which is called inside or outside the constructor.
			//// Currently, FxCop does not produce a warning if a virtual method is called indirectly
			//// through a delegate or through a lambda.

			var constructor = (ConstructorDeclarationSyntax)node;
			var constructorSymbol = semanticModel.GetDeclaredSymbol(constructor);
			var containingType = constructorSymbol.ContainingType;

			if (
				constructor.Body.DescendantNodes()
				.Where(x => x.Kind() == SyntaxKind.InvocationExpression)
					.Any(x => CallVirtualMethod((InvocationExpressionSyntax)x, semanticModel, containingType)))
			{
				var result = new EvaluationResult
								 {
									 Snippet = node.ToFullString(),
									 LinesOfCodeAffected = GetLinesOfCode(node)
								 };
				return Task.FromResult(result);
			}

			return Task.FromResult<EvaluationResult>(null);
		}
开发者ID:henrylle,项目名称:ArchiMetrics,代码行数:28,代码来源:DoNotCallOverridableMembersInConstructorRule.cs


示例20: RenameOneSymbol

        private static async Task<Tuple<bool, Solution>> RenameOneSymbol(Solution solution, OptionSet renameOptions)
        {
            // Go through all project and documents, lookup classes and fields inside them. 
            // If any field needs renaming, perform rename operation
            var changes = from project in solution.Projects
                          from document in project.Documents
                          let root = document.GetSyntaxRootAsync().Result
                          let semantic = document.GetSemanticModelAsync().Result
                          from @class in root.DescendantNodes().OfType<ClassDeclarationSyntax>()
                          let classSymbol = semantic.GetDeclaredSymbol(@class)
                          from field in classSymbol.GetMembers().OfType<IFieldSymbol>().Where(x => !x.IsImplicitlyDeclared)
                          where field.Name.StartsWith("_")
                          let newName = field.Name.Substring(1)
                          select Renamer.RenameSymbolAsync(solution, field, newName, renameOptions);

            // Linq is lazy, so nothing has been done yet. Try to get first element (this will start rename) and if it exists, await it and return new solution
            var change = changes.FirstOrDefault();
            if (change != null)
            {
                return Tuple.Create(true, await change);
            }
            else
            {
                return Tuple.Create(false, solution);
            }
        }
开发者ID:Novakov,项目名称:fdd-roslyn,代码行数:26,代码来源:Program.cs



注:本文中的Microsoft.CodeAnalysis.Solution类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CodeAnalysis.SolutionServices类代码示例发布时间:2022-05-26
下一篇:
C# CodeAnalysis.SemanticModel类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap