Reputation: 1306
I have a test solution with some code like this:
public class Class1
{
public string Foo { get; set; }
}
public class Business
{
public void DoStuff()
{
var c1 = new Class1();
}
}
If I find the type through some explicit means like this:
var doc = solution.Projects.First().Documents.First(x => x.Name == "Class1.cs");
var typeDef = (await doc.GetSyntaxRootAsync())
.DescendantNodes()
.OfType<TypeDeclarationSyntax>()
.Single(t => t.Identifier.ValueText == "Class1");
var symbol = (ITypeSymbol) (await doc.GetSemanticModelAsync()).GetDeclaredSymbol(typeDef);
var refs = await SymbolFinder.FindReferencesAsync(symbol, solution);
The refs value shows 1 reference in the business class
If I do it like this however:
var compiledProjects = await Tasks.Task.WhenAll(
solution.Projects.Select(
async x => await x.GetCompilationAsync()));
var potentialMatches = compiledProjects.SelectMany(x =>
x.GetSymbolsWithName(s => s.ToLower() == "foo", SymbolFilter.All)).ToArray();
foreach (var prop in potentialMatches)
{
var type = prop.ContainingType;
var refs = await SymbolFinder.FindReferencesAsync(type, solution);
}
Then refs has no values. Looking at the property values returned from the two instances (symbol and type) they look similar. Clearly I'm missing something around how the tree is evaluated but it's not clear to me what's wrong.
This is for a Stand-Alone code analysis project.
Any help appreciated.
Cheers
Upvotes: 1
Views: 199