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


C# Utilities.DiagnosticDescription类代码示例

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


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

示例1: EmitToArray

        internal static ImmutableArray<byte> EmitToArray(
            this Compilation compilation,
            EmitOptions options = null,
            CompilationTestData testData = null,
            DiagnosticDescription[] expectedWarnings = null)
        {
            var stream = new MemoryStream();
            MemoryStream pdbStream = 
                (compilation.Options.OptimizationLevel == OptimizationLevel.Debug) && !CLRHelpers.IsRunningOnMono() 
                ? new MemoryStream() 
                : null;

            var emitResult = compilation.Emit(
                peStream: stream,
                pdbStream: pdbStream,
                xmlDocumentationStream: null,
                win32Resources: null,
                manifestResources: null,
                options: options,
                testData: testData,
                getHostDiagnostics: null,
                cancellationToken: default(CancellationToken));

            Assert.True(emitResult.Success, "Diagnostics:\r\n" + string.Join("\r\n", emitResult.Diagnostics.Select(d => d.ToString())));

            if (expectedWarnings != null)
            {
                emitResult.Diagnostics.Verify(expectedWarnings);
            }

            return stream.ToImmutable();
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:32,代码来源:CompilationExtensions.cs

示例2: VerifyAsync

 protected override Task VerifyAsync(string source, string language, DiagnosticAnalyzer[] analyzers, DiagnosticDescription[] diagnostics, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, string rootNamespace = null)
 {
     Assert.True(analyzers != null && analyzers.Length > 0, "Must specify at least one diagnostic analyzer to test suppression");
     var compilation = CreateCompilation(source, language, analyzers, rootNamespace);
     compilation.VerifyAnalyzerDiagnostics(analyzers, onAnalyzerException: onAnalyzerException, logAnalyzerExceptionAsDiagnostics: logAnalyzerExceptionAsDiagnostics, expected: diagnostics);
     return Task.FromResult(false);
 }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:7,代码来源:SuppressMessageAttributeCompilerTests.cs

示例3: EmitToArray

        internal static ImmutableArray<byte> EmitToArray(
            this Compilation compilation, 
            bool metadataOnly = false,
            CompilationTestData testData = null, 
            DiagnosticDescription[] expectedWarnings = null)
        {
            var stream = new MemoryStream();

            var emitResult = compilation.Emit(
                peStream: stream,
                outputName: null,
                pdbFilePath: null,
                pdbStream: null,
                xmlDocumentationStream: null,
                cancellationToken: default(CancellationToken),
                win32Resources: null,
                manifestResources: null,
                metadataOnly: metadataOnly,
                testData: testData);

            Assert.True(emitResult.Success, "Diagnostics:\r\n" + string.Join("\r\n, ", emitResult.Diagnostics.Select(d => d.ToString())));

            if (expectedWarnings != null)
            {
                emitResult.Diagnostics.Verify(expectedWarnings);
            }

            return stream.ToImmutable();
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:29,代码来源:CompilationExtensions.cs

示例4: EmitToStream

        public static MemoryStream EmitToStream(this Compilation compilation, EmitOptions options = null, DiagnosticDescription[] expectedWarnings = null)
        {
            var stream = new MemoryStream();
            var emitResult = compilation.Emit(stream, options: options);
            Assert.True(emitResult.Success, "Diagnostics: " + string.Join(", ", emitResult.Diagnostics.Select(d => d.ToString())));

            if (expectedWarnings != null)
            {
                emitResult.Diagnostics.Verify(expectedWarnings);
            }

            stream.Position = 0;
            return stream;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:14,代码来源:CompilationExtensions.cs

示例5: EmitToStream

        public static Stream EmitToStream(this Compilation compilation, bool metadataOnly = false, DiagnosticDescription[] expectedWarnings = null)
        {
            var stream = new MemoryStream();
            var emitResult = metadataOnly ? compilation.EmitMetadataOnly(stream) : compilation.Emit(stream);
            Assert.True(emitResult.Success, "Diagnostics: " + string.Join(", ", emitResult.Diagnostics.Select(d => d.ToString())));

            if (expectedWarnings != null)
            {
                emitResult.Diagnostics.Verify(expectedWarnings);
            }

            stream.Position = 0;
            return stream;
        }
开发者ID:riversky,项目名称:roslyn,代码行数:14,代码来源:CompilationExtensions.cs

示例6: EmitToImageReference

 public static MetadataReference EmitToImageReference(
     this Compilation comp,
     EmitOptions options = null,
     bool embedInteropTypes = false,
     ImmutableArray<string> aliases = default(ImmutableArray<string>),
     DiagnosticDescription[] expectedWarnings = null)
 {
     var image = comp.EmitToArray(options, expectedWarnings: expectedWarnings);
     if (comp.Options.OutputKind == OutputKind.NetModule)
     {
         return ModuleMetadata.CreateFromImage(image).GetReference(display: comp.MakeSourceModuleName());
     }
     else
     {
         return AssemblyMetadata.CreateFromImage(image).GetReference(aliases: aliases, embedInteropTypes: embedInteropTypes, display: comp.MakeSourceAssemblySimpleName());
     }
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:17,代码来源:CompilationExtensions.cs

示例7: Verify

        protected override void Verify(string source, string language, DiagnosticAnalyzer[] analyzers, DiagnosticDescription[] expectedDiagnostics, Func<Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException = null, string rootNamespace = null)
        {
            using (var workspace = CreateWorkspaceFromFile(source, language, rootNamespace))
            {
                var documentId = workspace.Documents[0].Id;
                var document = workspace.CurrentSolution.GetDocument(documentId);
                var span = document.GetSyntaxRootAsync().Result.FullSpan;

                var actualDiagnostics = new List<Diagnostic>();
                foreach (var analyzer in analyzers)
                {
                    actualDiagnostics.AddRange(DiagnosticProviderTestUtilities.GetAllDiagnostics(analyzer, document, span, donotCatchAnalyzerExceptions: continueOnAnalyzerException == null));
                }

                actualDiagnostics.Verify(expectedDiagnostics);
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:17,代码来源:SuppressMessageAttributeTests.cs

示例8: VerifyAsync

        protected override async Task VerifyAsync(string source, string language, DiagnosticAnalyzer[] analyzers, DiagnosticDescription[] expectedDiagnostics, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = true, string rootNamespace = null)
        {
            using (var workspace = await CreateWorkspaceFromFileAsync(source, language, rootNamespace))
            {
                var documentId = workspace.Documents[0].Id;
                var document = workspace.CurrentSolution.GetDocument(documentId);
                var span = (await document.GetSyntaxRootAsync()).FullSpan;

                var actualDiagnostics = new List<Diagnostic>();
                foreach (var analyzer in analyzers)
                {
                    actualDiagnostics.AddRange(
                        await DiagnosticProviderTestUtilities.GetAllDiagnosticsAsync(analyzer, document, span, onAnalyzerException, logAnalyzerExceptionAsDiagnostics));
                }

                actualDiagnostics.Verify(expectedDiagnostics);
            }
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:18,代码来源:SuppressMessageAttributeTests.cs

示例9: EmitToArray

        internal static ImmutableArray<byte> EmitToArray(
            this Compilation compilation,
            EmitOptions options = null,
            CompilationTestData testData = null,
            DiagnosticDescription[] expectedWarnings = null,
            Stream pdbStream = null,
            IMethodSymbol debugEntryPoint = null,
            Stream sourceLinkStream = null,
            IEnumerable<EmbeddedText> embeddedTexts = null)
        {
            var peStream = new MemoryStream();

            if (pdbStream == null && compilation.Options.OptimizationLevel == OptimizationLevel.Debug && options?.DebugInformationFormat != DebugInformationFormat.Embedded)
            {
                if (MonoHelpers.IsRunningOnMono())
                {
                    options = (options ?? EmitOptions.Default).WithDebugInformationFormat(DebugInformationFormat.PortablePdb);
                }

                pdbStream = new MemoryStream();
            }

            var emitResult = compilation.Emit(
                peStream: peStream,
                pdbStream: pdbStream,
                xmlDocumentationStream: null,
                win32Resources: null,
                manifestResources: null,
                options: options,
                debugEntryPoint: debugEntryPoint,
                sourceLinkStream: sourceLinkStream,
                embeddedTexts: embeddedTexts,
                testData: testData,
                cancellationToken: default(CancellationToken));

            Assert.True(emitResult.Success, "Diagnostics:\r\n" + string.Join("\r\n", emitResult.Diagnostics.Select(d => d.ToString())));

            if (expectedWarnings != null)
            {
                emitResult.Diagnostics.Verify(expectedWarnings);
            }

            return peStream.ToImmutable();
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:44,代码来源:CompilationExtensions.cs

示例10: EmitToArray

        internal static ImmutableArray<byte> EmitToArray(
            this Compilation compilation, 
            bool metadataOnly = false,
            bool debug = false,
            CompilationTestData testData = null, 
            Guid mvid = default(Guid),
            DiagnosticDescription[] expectedWarnings = null)
        {
            var stream = new MemoryStream();

            if (mvid == default(Guid))
            {
                mvid = Guid.NewGuid();
            }

            var emitResult = compilation.Emit(
                executableStream: stream,
                outputName: null,
                pdbFilePath: debug ? "Compilation.pdb" : null,
                pdbStream: debug ? new MemoryStream() : null,
                xmlDocStream: null,
                cancellationToken: default(CancellationToken),
                win32Resources: null,
                manifestResources: null,
                moduleVersionId: mvid,
                metadataOnly: metadataOnly,
                testData: testData);

            Assert.True(emitResult.Success, "Diagnostics: " + string.Join(", ", emitResult.Diagnostics.Select(d => d.ToString())));

            if (expectedWarnings != null)
            {
                emitResult.Diagnostics.Verify(expectedWarnings);
            }

            return stream.ToImmutable();
        }
开发者ID:riversky,项目名称:roslyn,代码行数:37,代码来源:CompilationExtensions.cs

示例11: VerifyTokenDiagnostics

        // Generate a diagnostic on every token in the specified spans, and verify that only the specified diagnostics are not suppressed
        private void VerifyTokenDiagnostics(string markup, string language, DiagnosticDescription[] diagnostics)
        {
            string source;
            IList<TextSpan> spans;
            MarkupTestFile.GetSpans(markup, out source, out spans);
            Assert.True(spans.Count > 0, "Must specify a span within which to generate diagnostics on each token");

            Verify(source, language, new IDiagnosticAnalyzer[] { new WarningOnTokenAnalyzer(spans) }, diagnostics);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:10,代码来源:SuppressMessageAttributeTests.cs

示例12: Verify

 protected virtual void Verify(string source, string language, IDiagnosticAnalyzer[] analyzers, DiagnosticDescription[] diagnostics, string rootNamespace = null)
 {
     Assert.True(analyzers != null && analyzers.Length > 0, "Must specify at least one diagnostic analyzer to test suppression");
     var compilation = CreateCompilation(source, language, analyzers, rootNamespace);
     compilation.VerifyAnalyzerDiagnostics(analyzers, diagnostics);
 }
开发者ID:riversky,项目名称:roslyn,代码行数:6,代码来源:SuppressMessageAttributeTests.cs

示例13: CS0472WRN_NubExprIsConstBool


//.........这里部分代码省略.........
        W(new Guid?() != g);              // CS0472
        W(new Guid?() == h);              // no error
        W(new Guid?() != h);              // no error

        System.Console.WriteLine();

        W(null == null);                  // No error, because both sides are nullable, but of course
        W(null != null);                  // we could give a warning here as well.

        System.Console.WriteLine();

        //check comparisons with converted constants
        W((E?)1 == null);
        W(null != (E?)1);

        W((int?)1 == null);
        W(null != (int?)1);

        //check comparisons when null is converted 

        W(0 == (int?)null);
        W((int?)null != 0);
 
        W(0 == (E?)null);
        W((E?)null != 0);
    }
}
";

            string expected = @"ftftftftftftftftftftftft
ftftftftftftftftftftftft
tf
ftftftft";
            var fullExpected = new DiagnosticDescription[] {
                // (19,11): warning CS0472: The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'int?'
                //         W(i == null);            // CS0472
                Diagnostic(ErrorCode.WRN_NubExprIsConstBool, "i == null").WithArguments("false", "int", "int?").WithLocation(19, 11),
                // (20,11): warning CS0472: The result of the expression is always 'true' since a value of type 'int' is never equal to 'null' of type 'int?'
                //         W(i != null);            // CS0472
                Diagnostic(ErrorCode.WRN_NubExprIsConstBool, "i != null").WithArguments("true", "int", "int?").WithLocation(20, 11),
                // (23,11): warning CS8073: The result of the expression is always 'false' since a value of type 'System.Guid' is never equal to 'null' of type 'System.Guid?'
                //         W(g == null);            // CS0472
                Diagnostic(ErrorCode.WRN_NubExprIsConstBool2, "g == null").WithArguments("false", "System.Guid", "System.Guid?").WithLocation(23, 11),
                // (24,11): warning CS8073: The result of the expression is always 'true' since a value of type 'System.Guid' is never equal to 'null' of type 'System.Guid?'
                //         W(g != null);            // CS0472
                Diagnostic(ErrorCode.WRN_NubExprIsConstBool2, "g != null").WithArguments("true", "System.Guid", "System.Guid?").WithLocation(24, 11),
                // (28,11): warning CS0472: The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'short?'
                //         W(i == default(short?));            // CS0472
                Diagnostic(ErrorCode.WRN_NubExprIsConstBool, "i == default(short?)").WithArguments("false", "int", "short?").WithLocation(28, 11),
                // (29,11): warning CS0472: The result of the expression is always 'true' since a value of type 'int' is never equal to 'null' of type 'short?'
                //         W(i != default(short?));            // CS0472
                Diagnostic(ErrorCode.WRN_NubExprIsConstBool, "i != default(short?)").WithArguments("true", "int", "short?").WithLocation(29, 11),
                // (32,11): warning CS8073: The result of the expression is always 'false' since a value of type 'System.Guid' is never equal to 'null' of type 'System.Guid?'
                //         W(g == default(Guid?));             // CS0472
                Diagnostic(ErrorCode.WRN_NubExprIsConstBool2, "g == default(Guid?)").WithArguments("false", "System.Guid", "System.Guid?").WithLocation(32, 11),
                // (33,11): warning CS8073: The result of the expression is always 'true' since a value of type 'System.Guid' is never equal to 'null' of type 'System.Guid?'
                //         W(g != default(Guid?));             // CS0472
                Diagnostic(ErrorCode.WRN_NubExprIsConstBool2, "g != default(Guid?)").WithArguments("true", "System.Guid", "System.Guid?").WithLocation(33, 11),
                // (37,11): warning CS0472: The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'sbyte?'
                //         W(i == new sbyte?());            // CS0472
                Diagnostic(ErrorCode.WRN_NubExprIsConstBool, "i == new sbyte?()").WithArguments("false", "int", "sbyte?").WithLocation(37, 11),
                // (38,11): warning CS0472: The result of the expression is always 'true' since a value of type 'int' is never equal to 'null' of type 'sbyte?'
                //         W(i != new sbyte?());            // CS0472
                Diagnostic(ErrorCode.WRN_NubExprIsConstBool, "i != new sbyte?()").WithArguments("true", "int", "sbyte?").WithLocation(38, 11),
                // (41,11): warning CS8073: The result of the expression is always 'false' since a value of type 'System.Guid' is never equal to 'null' of type 'System.Guid?'
                //         W(g == new Guid?());             // CS0472
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:67,代码来源:SemanticErrorTests.cs

示例14: VerifyGeneratedCodeAnalyzerDiagnostics

 private static void VerifyGeneratedCodeAnalyzerDiagnostics(Compilation compilation, DiagnosticDescription[] expected, GeneratedCodeAnalysisFlags? generatedCodeAnalysisFlagsOpt)
 {
     var analyzers = new DiagnosticAnalyzer[] { new GeneratedCodeAnalyzer(generatedCodeAnalysisFlagsOpt) };
     compilation.VerifyAnalyzerDiagnostics(analyzers, null, null, logAnalyzerExceptionAsDiagnostics: false, expected: expected);
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:5,代码来源:DiagnosticAnalyzerTests.cs

示例15: TestConcurrentAnalyzer

        public void TestConcurrentAnalyzer()
        {
            if (Environment.ProcessorCount <= 1)
            {
                // Don't test for non-concurrent environment.
                return;
            }

            var builder = new StringBuilder();
            var typeCount = 100;
            var typeNames = new string[typeCount];
            for (int i = 1; i <= typeCount; i++)
            {
                var typeName = $"C{i}";
                typeNames[i - 1] = typeName;
                builder.Append($"\r\nclass {typeName} {{ }}");
            }

            var source = builder.ToString();
            var compilation = GetCompilationWithConcurrentBuildEnabled(source);
            compilation.VerifyDiagnostics();

            // Verify analyzer diagnostics for Concurrent analyzer only.
            var analyzers = new DiagnosticAnalyzer[] { new ConcurrentAnalyzer(typeNames) };
            var expected = new DiagnosticDescription[typeCount];
            for (int i = 0; i < typeCount; i++)
            {
                var typeName = $"C{i + 1}";
                expected[i] = Diagnostic(ConcurrentAnalyzer.Descriptor.Id, typeName)
                    .WithArguments(typeName)
                    .WithLocation(i + 2, 7);
            }

            compilation.VerifyAnalyzerDiagnostics(analyzers, expected: expected);

            // Verify analyzer diagnostics for Concurrent and NonConcurrent analyzer together (latter reports diagnostics only for error cases).
            analyzers = new DiagnosticAnalyzer[] { new ConcurrentAnalyzer(typeNames), new NonConcurrentAnalyzer() };
            compilation.VerifyAnalyzerDiagnostics(analyzers, expected: expected);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:39,代码来源:DiagnosticAnalyzerTests.cs


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