How to get all types 开发者_C百科in the assembly inside a macro attribute of kind MacroTargets.Assembly
in Nemerle?
The name tree contains all of the types. You can traverse and filter it yourself or you can call its GetTypeBuilders
method.
[ Nemerle.MacroUsage
( Nemerle.MacroPhase.WithTypedMembers
, Nemerle.MacroTargets.Assembly
)
]
macro ListTypes()
{
def PrintNameTree(node, depth)
{
repeat (depth)
Write(" ");
Write("|");
WriteLine(node.PartName);
unless (node.Children == null)
{
foreach (child in node.Children.Values)
PrintNameTree(child, depth + 1);
}
}
def env = ImplicitCTX().Env;
def names = env.NameTree;
PrintNameTree(names.NamespaceTree, 0);
}
In addition to the answer of Don Reba...
You should use Node.EnsureCached() method to ensure metadata cached.
精彩评论