开发者

Enumerate all types in an assembly inside a macro

开发者 https://www.devze.com 2023-03-30 09:13 出处:网络
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 y

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消