Is there a way to get all namespaces you're 'using' within a class through C# code?

前端 未结 3 1858
北荒
北荒 2021-02-05 17:41

Is there any way to get a List which contains all \'usings\' within a namespace/class?

For instance

using System;
using System         


        
3条回答
  •  旧时难觅i
    2021-02-05 17:59

    You can use Mono Cecil to read a class definition from an assembly and get a list of all the referenced types in each method. From there, you can extract a list of namespaces (fully qualified type name minus the last part).

提交回复
热议问题