I am trying to find fields with the specified attribute. I tried changing the FirstQuickFix example because, as I thought, this could be a good starting point. But if I run the code, nothing happens. Any ideas what is my main problem?
My understanding, after reading the Project Overview and walkthrough docs, is that I can request attributes for the token I found in the syntax tree. The syntax tree is an accurate tree view of the source code. The combination of a field declaration and its attributes is available through semantics. Or is my understanding completely wrong?
[ExportCodeIssueProvider("FirstQuickFix_", LanguageNames.CSharp)]
class CodeIssueProvider : ICodeIssueProvider
{
public IEnumerable<CodeIssue> GetIssues
(IDocument document, CommonSyntaxNode node, CancellationToken cancellationToken)
{
var tokens = from nodeOrToken in node.ChildNodesAndTokens()
where nodeOrToken.HasAnnotations(Type.GetType("myAttribute"))
select nodeOrToken.AsToken();
foreach (var token in tokens)
{
var issueDescription = string.Format("found!!!");
yield return new CodeIssue(CodeIssueKind.Info, token.Span, issueDescription);
}
}
}
Edit:
what I want to achieve is to find that. all fields with the myAttribute attribute:
namespace ConsoleApplication
{
class Program
{
[myAttribute]
string myField = "test";
public void testing()
{
Console.WriteLine(myField);
}
}
}
source
share