I'm trying to retrieve some type's namespace with Roslyn API, but my code is not working with external assemblies (types from NuGet packages, or from another external assembly):
var typeInfo = semanticModel.GetTypeInfo(typeSyntax);
var isFromSource = typeInfo.Type.Locations.Length > 0;
if (isFromSource)
{
var symbolInfo = semanticModel.GetSymbolInfo(typeSyntax);
//type's namespace:
return symbolInfo.Symbol.ContainingNamespace.ToString();
}
else
{
//Type is from some external assembly
return "";
}
How can i return the type's namespace in this case?
EDIT: I'm retrieving solution's documents with:
using (var ws = MSBuildWorkspace.Create())
{
var solution = await ws.OpenSolutionAsync(solutionPath);
return solution.Projects.SelectMany(p => p.Documents);
}