Get paths of assemblies used in Type

前端 未结 2 895
醉梦人生
醉梦人生 2020-12-10 06:43

I need a method that takes a Type and returns the paths of all assemblies that used in the type. I wrote this:

public static IEnumerable GetRef         


        
2条回答
  •  时光说笑
    2020-12-10 07:14

    I think i solved the Assembly.Load() problem by replacing it to Assembly.ReflectionOnlyLoad().

    now this is how my method looks like:

    public static IEnumerable GetReferencesAssembliesPaths(this Type type)
    {           
        yield return type.Assembly.Location;
    
        foreach (AssemblyName assemblyName in type.Assembly.GetReferencedAssemblies())
        {
            yield return Assembly.ReflectionOnlyLoad(assemblyName.FullName).Location;
        }
    }
    

    now the only left problem is the type.Assembly.GetReferencedAssemblies(), how do i get referenced assemblies from the type rather than from the assembly?

提交回复
热议问题