Why does Assembly.GetTypes() require references?

后端 未结 4 1979
[愿得一人]
[愿得一人] 2021-01-12 16:34

I want to get all of the types from my assembly, but I don\'t have the references, nor do I care about them. What does finding the interface types have to do with the refere

4条回答
  •  情歌与酒
    2021-01-12 17:14

    It seems to be a duplicate of Get Types defined in an assembly only, where the solution is:

    public static Type[] GetTypesLoaded(Assembly assembly)
    {
        Type[] types;
        try
        {
            types = assembly.GetTypes();
        }
        catch (ReflectionTypeLoadException e)
        {
            types = e.Types.Where(t => t != null).ToArray();
        }
    
        return types;    
    }
    

提交回复
热议问题