Domanda

I have this variable in C# which is part of a resharper plugin I am creating to throw a warning on all quoted values (not just strings).

                var sourceFile = _process.SourceFile;
                var file = sourceFile.GetPsiServices().Files.GetDominantPsiFile<CSharpLanguage>(sourceFile);

                if (file != null)
                {
                    var highlights = new List<HighlightingInfo>();

                    var stringHighlight = new RecursiveElementProcessor<IQuotedValue>(declaration =>
                    {
                        var docRange = declaration.GetDocumentRange();
                            highlights.Add(new HighlightingInfo(docRange, new MakeMethodVirtualSuggestion("Warning...")));
                    });

                   file.ProcessDescendants(stringHighlight);
                   commiter(new DaemonStageResult(highlights));
                }

It works when using IMethodDeclaration but can't figure out how to pick up an IQuotedValue value. Is the RecursiveElementProcessor the wrong thing to use in this situation? Any and all help is appreciated greatly been trying to figure this out for many many hours now. Thanks in advance.

È stato utile?

Soluzione

IQuotedValue is a XAML element - it doesn't get used in the C# syntax tree. The best thing to do is look for elements of ILiteralExpression, or ICSharpLiteralExpression, and then look at the Literal property to see what it is - true, false a number, character or string.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top