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


C# Compilation.WithOptions方法代码示例

本文整理汇总了C#中Compilation.WithOptions方法的典型用法代码示例。如果您正苦于以下问题:C# Compilation.WithOptions方法的具体用法?C# Compilation.WithOptions怎么用?C# Compilation.WithOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Compilation的用法示例。


在下文中一共展示了Compilation.WithOptions方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDiagnostics

        public IEnumerable<Diagnostic> GetDiagnostics(Compilation compilation)
        {
            if (diagnosticAnalyzers.IsDefaultOrEmpty)
            {
                return new Diagnostic[0];
            }

            var compilationOptions = compilation.Language == LanguageNames.CSharp
                ? (CompilationOptions)new CS.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
                : new VB.VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
            compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(
                diagnosticAnalyzers.SelectMany(analyzer => analyzer.SupportedDiagnostics)
                    .Select(diagnostic =>
                        new KeyValuePair<string, ReportDiagnostic>(diagnostic.Id, ReportDiagnostic.Warn)));

            var modifiedCompilation = compilation.WithOptions(compilationOptions);

            using (var tokenSource = new CancellationTokenSource())
            {
                var compilationWithAnalyzer = modifiedCompilation.WithAnalyzers(diagnosticAnalyzers, null,
                    tokenSource.Token);

                return compilationWithAnalyzer.GetAnalyzerDiagnosticsAsync().Result;
            }
        }
开发者ID:Godin,项目名称:sonarlint-vs,代码行数:25,代码来源:DiagnosticsRunner.cs

示例2: GetDiagnostics

        private static IEnumerable<Diagnostic> GetDiagnostics(Compilation compilation,
            DiagnosticAnalyzer diagnosticAnalyzer)
        {
            using (var tokenSource = new CancellationTokenSource())
            {
                var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
                compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(
                    diagnosticAnalyzer.SupportedDiagnostics
                        .Select(diagnostic =>
                            new KeyValuePair<string, ReportDiagnostic>(diagnostic.Id, ReportDiagnostic.Warn)));

                var compilationWithOptions = compilation.WithOptions(compilationOptions);
                var compilationWithAnalyzer = compilationWithOptions
                    .WithAnalyzers(ImmutableArray.Create(diagnosticAnalyzer), null, tokenSource.Token);

                return compilationWithAnalyzer.GetAnalyzerDiagnosticsAsync().Result;
            }
        }
开发者ID:OsirisTerje,项目名称:sonarlint-vs,代码行数:18,代码来源:Verifier.cs

示例3: EnableAnalyzer

 private static Compilation EnableAnalyzer(DiagnosticAnalyzer analyzer, Compilation compilation)
 {
     return compilation
         .WithOptions(
             compilation
                 .Options
                 .WithSpecificDiagnosticOptions(
                     analyzer
                         .SupportedDiagnostics
                         .Select(x =>
                             KeyValuePair.Create(x.Id, ReportDiagnostic.Default))
                             .ToImmutableDictionaryOrEmpty()));
 }
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:13,代码来源:DiagnosticAnalyzerTestBase.cs

示例4: CompilationWithAnalyzers

        private CompilationWithAnalyzers(Compilation compilation, ImmutableArray<DiagnosticAnalyzer> analyzers, CompilationWithAnalyzersOptions analysisOptions, CancellationToken cancellationToken)
        {
            VerifyArguments(compilation, analyzers, analysisOptions);

            compilation = compilation
                .WithOptions(compilation.Options.WithReportSuppressedDiagnostics(analysisOptions.ReportSuppressedDiagnostics))
                .WithEventQueue(new AsyncQueue<CompilationEvent>());
            _compilation = compilation;
            _analyzers = analyzers;
            _analysisOptions = analysisOptions;
            _cancellationToken = cancellationToken;

            _compilationData = new CompilationData(_compilation);
            _analysisState = new AnalysisState(analyzers, _compilationData);
            _analysisResult = new AnalysisResult(analysisOptions.LogAnalyzerExecutionTime, analyzers);
            _driverPool = new ObjectPool<AnalyzerDriver>(() => _compilation.AnalyzerForLanguage(analyzers, AnalyzerManager.Instance));
            _executingConcurrentTreeTasksOpt = analysisOptions.ConcurrentAnalysis ? new Dictionary<SyntaxTree, Tuple<Task, CancellationTokenSource>>() : null;
            _concurrentTreeTaskTokensOpt = analysisOptions.ConcurrentAnalysis ? new Dictionary<Task, int>() : null;
            _executingCompilationOrNonConcurrentTreeTask = null;
        }
开发者ID:antonfirsov,项目名称:roslyn,代码行数:20,代码来源:CompilationWithAnalyzers.cs

示例5: Compile

		/// <summary>
		///   Compiles S# <paramref name="project" /> and returns the bytes of the compiled assembly.
		/// </summary>
		/// <param name="project">The project that should be compiled.</param>
		/// <param name="peBytes">Returns the compiled assembly.</param>
		/// <param name="pdbBytes">The returns the compiled program database.</param>
		public void Compile([NotNull] Project project, out byte[] peBytes, out byte[] pdbBytes)
		{
			Requires.NotNull(project, nameof(project));

			Compilation = project.GetCompilationAsync().Result;

			var diagnosticOptions = Compilation.Options.SpecificDiagnosticOptions.Add("CS0626", ReportDiagnostic.Suppress);
			var options = (CSharpCompilationOptions)Compilation.Options;
			options = options.WithAllowUnsafe(true).WithSpecificDiagnosticOptions(diagnosticOptions);

			if (!Diagnose())
				throw new CompilationException();

			Compilation = Compilation.WithOptions(options);
			Compilation = Normalizer.ApplyNormalizers(Compilation);

			EmitInMemory(out peBytes, out pdbBytes);
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:24,代码来源:Compiler.cs

示例6: Compile

		/// <summary>
		///     Compiles S# <paramref name="project" /> and returns the bytes of the compiled assembly.
		/// </summary>
		/// <param name="project">The project that should be compiled.</param>
		/// <param name="peBytes">Returns the compiled assembly.</param>
		/// <param name="pdbBytes">The returns the compiled program database.</param>
		public void Compile([NotNull] Project project, out byte[] peBytes, out byte[] pdbBytes)
		{
			Requires.NotNull(project, () => project);

			Compilation = project.GetCompilationAsync().Result;

			var diagnosticOptions = Compilation.Options.SpecificDiagnosticOptions.Add("CS0626", ReportDiagnostic.Suppress);
			var options = Compilation.Options.WithSpecificDiagnosticOptions(diagnosticOptions);
			var syntaxGenerator = SyntaxGenerator.GetGenerator(project.Solution.Workspace, LanguageNames.CSharp);

			if (!Diagnose())
				throw new CompilationException();

			Compilation = Compilation.WithOptions(options);
			ApplyNormalizers(syntaxGenerator);

			EmitInMemory(out peBytes, out pdbBytes);
		}
开发者ID:cubeme,项目名称:safety-sharp,代码行数:24,代码来源:Compiler.cs

示例7: GetAllDiagnostics

        private static IEnumerable<Diagnostic> GetAllDiagnostics(Compilation compilation,
            IEnumerable<DiagnosticAnalyzer> diagnosticAnalyzers)
        {
            using (var tokenSource = new CancellationTokenSource())
            {
                var compilationOptions = compilation.Language == LanguageNames.CSharp
                    ? (CompilationOptions)new CS.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
                    : new VB.VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
                var supportedDiagnostics = diagnosticAnalyzers
                        .SelectMany(analyzer => analyzer.SupportedDiagnostics)
                        .ToList();
                compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(
                    supportedDiagnostics
                        .Select(diagnostic =>
                            new KeyValuePair<string, ReportDiagnostic>(diagnostic.Id, ReportDiagnostic.Warn))
                        .Union(
                            new[]
                            {
                                new KeyValuePair<string, ReportDiagnostic>(AnalyzerFailedDiagnosticId, ReportDiagnostic.Error)
                            }));

                var compilationWithOptions = compilation.WithOptions(compilationOptions);
                var compilationWithAnalyzer = compilationWithOptions
                    .WithAnalyzers(
                        diagnosticAnalyzers.ToImmutableArray(),
                        cancellationToken: tokenSource.Token);

                return compilationWithAnalyzer.GetAllDiagnosticsAsync().Result;
            }
        }
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:30,代码来源:Verifier.cs

示例8: GetDiagnostics

        internal static IEnumerable<Diagnostic> GetDiagnostics(Compilation compilation,
            DiagnosticAnalyzer diagnosticAnalyzer)
        {
            using (var tokenSource = new CancellationTokenSource())
            {
                var compilationOptions = compilation.Language == LanguageNames.CSharp
                    ? (CompilationOptions)new CS.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
                    : new VB.VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
                compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(
                    diagnosticAnalyzer.SupportedDiagnostics
                        .Select(diagnostic =>
                            new KeyValuePair<string, ReportDiagnostic>(diagnostic.Id, ReportDiagnostic.Warn))
                        .Union(
                            new KeyValuePair<string, ReportDiagnostic>[]
                            {
                                new KeyValuePair<string, ReportDiagnostic>("AD0001", ReportDiagnostic.Error)
                            }));

                var compilationWithOptions = compilation.WithOptions(compilationOptions);
                var compilationWithAnalyzer = compilationWithOptions
                    .WithAnalyzers(
                        ImmutableArray.Create(diagnosticAnalyzer),
                        cancellationToken: tokenSource.Token);

                var diagnostics = compilationWithAnalyzer.GetAllDiagnosticsAsync().Result;
                diagnostics.Where(d => d.Id == "AD0001").Should().BeEmpty();

                return diagnostics.Where(d => d.Id == diagnosticAnalyzer.SupportedDiagnostics.Single().Id);
            }
        }
开发者ID:jakobehn,项目名称:sonarlint-vs,代码行数:30,代码来源:Verifier.cs


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