3

I am using the SymbolFinder.FindDeclarationsAsync() method to find a symbol declared in a project. But the method does not match for fully qualified names.

var symbols = SymbolFinder.FindDeclarationsAsync(projects, "String", true).Result;

The above code returns multiple declarations for String like System.String, System.Data.String, System.Reflection.String, etc

Is there any way to specify "System.String" and get only the ISymbol object for the specified fully qualified name?

CasKaDev
  • 123
  • 1
  • 5
  • FindDeclarationsAsync is the API you use to find symbols when you want to search *not* by full name. See Kevin's answer for the right API. – Jason Malinowski Dec 30 '14 at 18:14

1 Answers1

3

It sounds like you are looking for Compilation.GetTypeByMetadataName().

Kevin Pilch
  • 11,485
  • 1
  • 39
  • 41
  • This method is currently broken; see https://github.com/dotnet/roslyn/issues/3864 for details. Scroll down for a workaround. – Grault Dec 15 '15 at 23:43
  • Broken is a rather strong wording. That is actually what we designed The method to do. We considered adding a version of it on IAssemblySymbol to handle that case, but haven't yet. We could also potentially make the method accept assembly qualified names. – Kevin Pilch Dec 16 '15 at 16:54
  • (I didn't intend "broken" to be controversial, but I couldn't think of a succinct way to represent the conversation on GitHub.) I took the bug OP's tack and made a method `IEnumerable ResolveType` whose result I generally call `First` on. So if I have a vote, that's it. – Grault Dec 16 '15 at 17:22