当前位置: 首页>>代码示例>>C#>>正文


C# CodeAnalysis.Project类代码示例

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


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

示例1: RunTest

        public LineCoverage[] RunTest(Project project,
            RewrittenDocument rewrittenDocument,
            MethodDeclarationSyntax method,
            ISemanticModel semanticModel,
            string[] rewrittenAssemblies)
        {
            var testClass = method.GetParentClass();
            var rewrittenTestClass =
                rewrittenDocument.SyntaxTree
                    .GetRoot()
                    .DescendantNodes()
                    .OfType<ClassDeclarationSyntax>().First(x => x.Identifier.ToString() == testClass.Identifier.ToString());

            var fixtureDetails = _testsExtractor.GetTestFixtureDetails(rewrittenTestClass, semanticModel);
            var allReferences = _solutionExplorer.GetAllProjectReferences(project.Name);

            fixtureDetails.Cases.RemoveAll(x => x.MethodName != method.Identifier.ToString());

            if (fixtureDetails.Cases.Count == 0)
                return null;

            var compiledTestInfo = new CompiledTestFixtureInfo
            {
                AllReferences = allReferences.Union(rewrittenAssemblies).ToArray(),
                TestDocumentPath = rewrittenDocument.DocumentPath,
                SemanticModel = semanticModel
            };

            var coverage = RunTestFixture(fixtureDetails, compiledTestInfo, project.Name);

            return coverage;
        }
开发者ID:pzielinski86,项目名称:RuntimeTestCoverage,代码行数:32,代码来源:TestRunner.cs

示例2: GenerateTypeOptionsResult

		public GenerateTypeOptionsResult(
			Accessibility accessibility,
			TypeKind typeKind,
			string typeName,
			Project project,
			bool isNewFile,
			string newFileName,
			IList<string> folders,
			string fullFilePath,
			Document existingDocument,
			bool areFoldersValidIdentifiers,
			bool isCancelled = false)
		{
			this.Accessibility = accessibility;
			this.TypeKind = typeKind;
			this.TypeName = typeName;
			this.Project = project;
			this.IsNewFile = isNewFile;
			this.NewFileName = newFileName;
			this.Folders = folders;
			this.FullFilePath = fullFilePath;
			this.ExistingDocument = existingDocument;
			this.AreFoldersValidIdentifiers = areFoldersValidIdentifiers;
			this.IsCancelled = isCancelled;
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:25,代码来源:GenerateTypeOptionsResult.cs

示例3: RunAllTestsInDocument

        public LineCoverage[] RunAllTestsInDocument(RewrittenDocument rewrittenDocument,
            ISemanticModel semanticModel,
            Project project,
            string[] rewrittenAssemblies)
        {
            var allReferences = _solutionExplorer.GetAllProjectReferences(project.Name);

            var compiledTestInfo = new CompiledTestFixtureInfo
            {
                AllReferences = allReferences.Union(rewrittenAssemblies).ToArray(),
                TestDocumentPath = rewrittenDocument.DocumentPath,
                SemanticModel = semanticModel
            };

            var coverage = new List<LineCoverage>();

            var testClasses = _testsExtractor.GetTestClasses(rewrittenDocument.SyntaxTree.GetRoot());

            if (testClasses.Length == 0)
                return null;

            foreach (ClassDeclarationSyntax testClass in testClasses)
            {
                compiledTestInfo.TestClass = testClass;

                var partialCoverage = RunAllTestsInFixture(compiledTestInfo, project.Name);
                coverage.AddRange(partialCoverage);
            }

            return coverage.ToArray();
        }
开发者ID:pzielinski86,项目名称:RuntimeTestCoverage,代码行数:31,代码来源:TestRunner.cs

示例4: GetDiagnostics

		internal static async Task<ImmutableArray<Diagnostic>> GetDiagnostics (Project project, List<DiagnosticAnalyzer> providers, CancellationToken token)
		{
			var analyzers = ImmutableArray<DiagnosticAnalyzer>.Empty.AddRange (providers);
			try {
				var compilation = await project.GetCompilationAsync (token).ConfigureAwait (false);
				CompilationWithAnalyzers compilationWithAnalyzer;
				var options = new CompilationWithAnalyzersOptions (
					null,
					delegate (Exception exception, DiagnosticAnalyzer analyzer, Diagnostic diag) {
						LoggingService.LogError ("Exception in diagnostic analyzer " + diag.Id + ":" + diag.GetMessage (), exception);
					},
					true,
					false
				);

				compilationWithAnalyzer = compilation.WithAnalyzers (analyzers, options);
				if (token.IsCancellationRequested)
					return ImmutableArray<Diagnostic>.Empty;

				return await compilationWithAnalyzer.GetAnalyzerDiagnosticsAsync ().ConfigureAwait (false);
			} catch (Exception) {
				return ImmutableArray<Diagnostic>.Empty;
			} finally {
				CompilationWithAnalyzers.ClearAnalyzerState (analyzers);
			}
		}
开发者ID:kdubau,项目名称:monodevelop,代码行数:26,代码来源:AnalyzeWholeSolutionHandler.cs

示例5: RoslynCompiledItem

        public RoslynCompiledItem(Project project, CSharpCompilation
            compilation)
        {
            Project = project;

            Compilation = compilation;
        }
开发者ID:pzielinski86,项目名称:RuntimeTestCoverage,代码行数:7,代码来源:RoslynCompiledItem.cs

示例6: TryCreateCompilation

    static public bool TryCreateCompilation(Options options, out Task<Compilation> cu, out MSBuildWorkspace workspace, out Project project) 
    {
      Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn(out cu) != null); 
      Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn(out workspace) != null);

      Output.WriteLine("Opening the solution {0}", options.Solution);

      workspace = MSBuildWorkspace.Create();
      cu = null;
      project = null;
      try
      {
        if (options.Project != null && options.Solution != null)
        {
          return CreateCompilationFromSolution(options, workspace, out cu, out project);
        }
        else
        {
          Output.WriteError("Failed to parse either the Project or Solution");
          // not implemented;
          return false;
        }
      }
      catch(Exception e)
      {
        Output.WriteError("Error while parsing the .csproj file. Exception from Roslyn: {0}", e.ToString());
        cu = null;
        return false;
      }
    }
开发者ID:scottcarr,项目名称:ccbot,代码行数:30,代码来源:CompilationUnit.cs

示例7: MoveTypeNodes

		private static Project MoveTypeNodes(SemanticModel model, ImmutableArray<TypeToRemove> typesToRemove,
			Func<string, string> typeFolderGenerator, Project project, CancellationToken token)
		{
			var projectName = project.Name;

			foreach (var typeToRemove in typesToRemove)
			{
				token.ThrowIfCancellationRequested();
				var fileName = $"{typeToRemove.Symbol.Name}.cs";

				var containingNamespace = typeToRemove.Symbol.GetContainingNamespace();
				var typeFolder = typeFolderGenerator(containingNamespace).Replace(
					projectName, string.Empty);

				if (typeFolder.StartsWith("\\"))
				{
					typeFolder = typeFolder.Remove(0, 1);
				}

				project = project.AddDocument(fileName,
					typeToRemove.Declaration.GetCompilationUnitForType(model, containingNamespace),
					folders: !string.IsNullOrWhiteSpace(typeFolder) ?
						new[] { typeFolder } : null).Project;
			}

			return project;
		}
开发者ID:JasonBock,项目名称:CompilerAPIBook,代码行数:27,代码来源:ExtractTypesToFilesCodeRefactoringProvider.cs

示例8: FixEFModelAsync

        private async Task<Solution> FixEFModelAsync(Project project, Compilation compilation,
            IEnumerable<IClassAssumption> classAssumptions, IEnumerable<IPropertyAssumption> propertyAssumptions, ObjectTheoremResult objectTheoremResult,
            CancellationToken cancellationToken)
        {
            Trace.WriteLine("FixEFModelAsync");
            try
            {
                var newSolution = project.Solution;

                foreach (var syntaxTree in compilation.SyntaxTrees)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var syntaxRoot = await syntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);
                    var semanticModel = compilation.GetSemanticModel(syntaxTree);

                    var rewriter = new AttributeAssumptionsRewriter(semanticModel, classAssumptions, propertyAssumptions, objectTheoremResult, cancellationToken);
                    var newSyntaxRoot = rewriter.Visit(syntaxRoot);

                    cancellationToken.ThrowIfCancellationRequested();

                    var documentId = newSolution.GetDocumentId(syntaxTree);
                    newSolution = newSolution.WithDocumentSyntaxRoot(documentId, newSyntaxRoot);
                }

                return newSolution;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
                throw;
            }
        }
开发者ID:RicardoNiepel,项目名称:Z3.ObjectTheorem,代码行数:33,代码来源:CodeFixProvider.cs

示例9: ProjectAnalysisResult

        public ProjectAnalysisResult(Project project, ImmutableArray<Diagnostic> diagnostics)
        {
            Contract.Requires(project != null);
            Project = project;

            Diagnostics = diagnostics;
        }
开发者ID:SergeyTeplyakov,项目名称:ErrorProne.NET,代码行数:7,代码来源:AnalyzerRunner.cs

示例10: Execute

		public override bool Execute()
		{
			if (Language != CSharp)
			{
				Log.LogError("Unsupported language {0}.", Language);
				return false;
			}

			Project = this.GetOrAddProject(ProjectFullPath);
			if (cancellation.IsCancellationRequested)
			{
				Log.LogWarning("Cancellation was requested. Aborting task.");
				return false;
			}

			Compilation = Project.GetCompilationAsync(cancellation.Token).Result;

			var logWarnings = false;
			if (!string.IsNullOrEmpty(LogWarnings) && bool.TryParse(LogWarnings, out logWarnings) && logWarnings)
			{
				var diagnostics = Compilation.GetDiagnostics(cancellation.Token);
				if (diagnostics.Any(d => d.Severity == DiagnosticSeverity.Error))
					Log.LogWarning("Code generation may not be complete, since there are compilation errors: " +
						string.Join(Environment.NewLine, diagnostics.Select(d => d.GetMessage())));
			}

			return true;
		}
开发者ID:kzu,项目名称:clide,代码行数:28,代码来源:CSharpTask.cs

示例11: AnalyzeOutOfProcAsync

        private async Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult>> AnalyzeOutOfProcAsync(
            RemoteHostClient client, CompilationWithAnalyzers analyzerDriver, Project project, CancellationToken cancellationToken)
        {
            var solution = project.Solution;

            var snapshotService = solution.Workspace.Services.GetService<ISolutionChecksumService>();

            // TODO: this should be moved out
            var hostChecksums = GetHostAnalyzerReferences(snapshotService, _analyzerService.GetHostAnalyzerReferences(), cancellationToken);
            var analyzerMap = CreateAnalyzerMap(analyzerDriver.Analyzers.Where(a => !a.MustRunInProcess()));
            if (analyzerMap.Count == 0)
            {
                return DiagnosticAnalysisResultMap.Create(ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>.Empty, ImmutableDictionary<DiagnosticAnalyzer, AnalyzerTelemetryInfo>.Empty);
            }

            // TODO: send telemetry on session
            using (var session = await client.CreateCodeAnalysisServiceSessionAsync(solution, cancellationToken).ConfigureAwait(false))
            {
                var argument = new DiagnosticArguments(
                    analyzerDriver.AnalysisOptions.ReportSuppressedDiagnostics,
                    analyzerDriver.AnalysisOptions.LogAnalyzerExecutionTime,
                    project.Id, hostChecksums, analyzerMap.Keys.ToArray());

                var result = await session.InvokeAsync(
                    WellKnownServiceHubServices.CodeAnalysisService_CalculateDiagnosticsAsync,
                    new object[] { argument },
                    (s, c) => GetCompilerAnalysisResultAsync(s, analyzerMap, project, c)).ConfigureAwait(false);

                ReportAnalyzerExceptions(project, result.Exceptions);

                return result;
            }
        }
开发者ID:tvsonar,项目名称:roslyn,代码行数:33,代码来源:OutOfProcDiagnosticAnalyzerExecutor.cs

示例12: AnalyzeAsync

        public async Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult>> AnalyzeAsync(CompilationWithAnalyzers analyzerDriver, Project project, CancellationToken cancellationToken)
        {
            var remoteHostClient = await project.Solution.Workspace.Services.GetService<IRemoteHostClientService>().GetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false);
            if (remoteHostClient == null)
            {
                // remote host is not running. this can happen if remote host is disabled.
                return await AnalyzeInProcAsync(analyzerDriver, project, cancellationToken).ConfigureAwait(false);
            }

            // TODO: later, make sure we can run all analyzer on remote host. 
            //       for now, we will check whether built in analyzer can run on remote host and only those run on remote host.
            var inProcResultTask = AnalyzeInProcAsync(CreateAnalyzerDriver(analyzerDriver, a => a.MustRunInProcess()), project, cancellationToken);
            var outOfProcResultTask = AnalyzeOutOfProcAsync(remoteHostClient, analyzerDriver, project, cancellationToken);

            // run them concurrently in vs and remote host
            await Task.WhenAll(inProcResultTask, outOfProcResultTask).ConfigureAwait(false);

            // make sure things are not cancelled
            cancellationToken.ThrowIfCancellationRequested();

            // merge 2 results
            return DiagnosticAnalysisResultMap.Create(
                inProcResultTask.Result.AnalysisResult.AddRange(outOfProcResultTask.Result.AnalysisResult),
                inProcResultTask.Result.TelemetryInfo.AddRange(outOfProcResultTask.Result.TelemetryInfo));
        }
开发者ID:tvsonar,项目名称:roslyn,代码行数:25,代码来源:OutOfProcDiagnosticAnalyzerExecutor.cs

示例13: CreateDescriptionBuilder

 internal override AbstractDescriptionBuilder CreateDescriptionBuilder(
     IVsObjectBrowserDescription3 description,
     ObjectListItem listItem,
     Project project)
 {
     return new DescriptionBuilder(description, this, listItem, project);
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:7,代码来源:ObjectBrowserLibraryManager.cs

示例14: PSharpProject

 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="project">Project</param>
 public PSharpProject(Project project)
 {
     this.Project = project;
     this.PSharpPrograms = new List<PSharpProgram>();
     this.PPrograms = new List<PProgram>();
     this.ProgramMap = new Dictionary<IPSharpProgram, SyntaxTree>();
 }
开发者ID:jerickmsft,项目名称:PSharp,代码行数:11,代码来源:PSharpProject.cs

示例15: RewriteDocumentWithAssemblyInfo

        public RewrittenDocument RewriteDocumentWithAssemblyInfo(Project currentProject, Project[] allProjects, string documentPath, string documentContent)
        {
            var attrs = CreateInternalVisibleToAttributeList(currentProject, allProjects);
            var rewrittenDocument = RewriteDocument(currentProject, documentPath, documentContent, attrs);

            return rewrittenDocument;
        }
开发者ID:pzielinski86,项目名称:RuntimeTestCoverage,代码行数:7,代码来源:SolutionRewriter.cs


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