I cannot find a nested class using the Roslyn method Compilation.GetTypeByMetaDataName().
For instance:
var tree = CSharpSyntaxTree.ParseText(@"
using System;
namespace MyNamespace
{
public class MyClass
{
public class MyInnerClass
{
}
}
}
");
var Mscorlib = new MetadataFileReference(typeof(object).Assembly.Location);
var compilation = CSharpCompilation.Create("MyCompilation",
syntaxTrees: new[] { tree }, references: new[] { Mscorlib });
var outerClass = compilation.GetTypeByMetadataName("MyNamespace.MyClass");
var innerClass = compilation.GetTypeByMetadataName("MyNamespace.MyClass.MyInnerClass");
Is it possible to extract nested types using their fully qualified names?
I understand that one work around would be to first check if the containing type contains any types using INamespaceorTypeSymbol.GetTypeMembers(), but I would probably not go this way. I would suggest that a method GetTypeByMetaDataName()should work for any type, nested or otherwise.
source
share