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


C# SemanticModel.GetDiagnostics方法代码示例

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


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

示例1: GetUnnecessaryImports

		public static IEnumerable<SyntaxNode> GetUnnecessaryImports(SemanticModel semanticModel, SyntaxNode root, CancellationToken cancellationToken)
		{
			var diagnostics = semanticModel.GetDiagnostics(cancellationToken: cancellationToken);
			if (!diagnostics.Any())
			{
				return null;
			}

			var unnecessaryImports = new HashSet<UsingDirectiveSyntax>();

			foreach (var diagnostic in diagnostics)
			{
				if (diagnostic.Id == "CS8019")
				{
					var node = root.FindNode(diagnostic.Location.SourceSpan) as UsingDirectiveSyntax;

					if (node != null)
					{
						unnecessaryImports.Add(node);
					}
				}
			}

			if (cancellationToken.IsCancellationRequested || !unnecessaryImports.Any())
			{
				return null;
			}

			return unnecessaryImports;
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:30,代码来源:CSharpRemoveUnnecessaryImportsService.cs

示例2: GetUnusedImportDirectives

        private static HashSet<SyntaxNode> GetUnusedImportDirectives(SemanticModel model, CancellationToken cancellationToken)
        {
            HashSet<SyntaxNode> unusedImportDirectives = new HashSet<SyntaxNode>();
            SyntaxNode root = model.SyntaxTree.GetRoot(cancellationToken);
            foreach (Diagnostic diagnostic in model.GetDiagnostics(null, cancellationToken).Where(d => d.Id == "CS8019" || d.Id == "CS0105"))
            {
                UsingDirectiveSyntax usingDirectiveSyntax = root.FindNode(diagnostic.Location.SourceSpan, false, false) as UsingDirectiveSyntax;
                if (usingDirectiveSyntax != null)
                {
                    unusedImportDirectives.Add(usingDirectiveSyntax);
                }
            }

            return unusedImportDirectives;
        }
开发者ID:joymon,项目名称:joyful-visualstudio,代码行数:15,代码来源:MoveClassToFile.cs

示例3: Visitor

 public Visitor(SemanticModel model)
     : base(SyntaxWalkerDepth.Trivia)
 {
     _model = model;
     _modelDiagnostic = _model.GetDiagnostics();
 }
开发者ID:Runt-Editor,项目名称:Runt,代码行数:6,代码来源:Highlighter.cs

示例4: GetPointDiagnostics

        private async Task<ImmutableArray<Diagnostic>> GetPointDiagnostics(TextSpan location, List<string> diagnosticIds)
        {
            _document = _workspace.GetDocument(_document.FilePath);
            _semanticModel = await _document.GetSemanticModelAsync();
            var diagnostics = _semanticModel.GetDiagnostics();

            //Restrict diagnostics only to missing usings
            return diagnostics.Where(d => d.Location.SourceSpan.Contains(location) &&
                    diagnosticIds.Contains(d.Id)).ToImmutableArray();
        }
开发者ID:GeeBook,项目名称:omnisharp-roslyn,代码行数:10,代码来源:FixUsings.cs

示例5: HasErrors

 private static bool HasErrors(SemanticModel semanticModel, SyntaxNode node)
 {
     var diags = semanticModel.GetDiagnostics(node.Span);
     if (diags.Any(d => d.Id.StartsWith("CS"))) return true;
     return false;
 }
开发者ID:haroldhues,项目名称:code-cracker,代码行数:6,代码来源:ComputeExpressionAnalyzer.cs

示例6: GetSemantic

        private void GetSemantic(string code, out SemanticModel model, out int pos)
        {
            var tree = CSharpSyntaxTree.ParseText(code);

            //var writer = new ConsoleDumpWalker();
            //writer.Visit(tree.GetRoot());

            var refs = AssemblyUtility.AllReferencedAssemblyLocations
                .Distinct()
                .Select(x => MetadataReference.CreateFromFile(x));

            var compilation = CSharpCompilation.Create(
                "MyCompilation",
                syntaxTrees: new[] { tree },
                references: refs);
            model = compilation.GetSemanticModel(tree);

            var diags = model.GetDiagnostics();
            foreach (var diag in diags)
            {
                if (diag.Id == "CS8019") continue;
                Console.WriteLine(diag);
                Assert.Fail();
            }

            var ns = tree.GetRoot().DescendantNodes().OfType<NamespaceDeclarationSyntax>().First();
            pos = ns.OpenBraceToken.SpanStart;

            // if we use that as a "container" then we get what's in the container *only*
            // not what we want here, then we have to use the position to determine *scope*
            //var ss = model.GetDeclaredSymbol(ns);
        }
开发者ID:nul800sebastiaan,项目名称:Zbu.ModelsBuilder,代码行数:32,代码来源:RoslynTests.cs


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