Пример #1
0
    public static java.lang.ClassLoader latestUserDefinedLoader()
    {
        // testing shows that it is cheaper the get the full stack trace and then look at a few frames than getting the frames individually
        StackTrace trace = new StackTrace(2, false);

        for (int i = 0; i < trace.FrameCount; i++)
        {
            StackFrame frame  = trace.GetFrame(i);
            MethodBase method = frame.GetMethod();
            if (method == null)
            {
                continue;
            }
            Type type = method.DeclaringType;
            if (type != null)
            {
                TypeWrapper tw = ClassLoaderWrapper.GetWrapperFromType(type);
                if (tw != null)
                {
                    ClassLoaderWrapper  classLoader = tw.GetClassLoader();
                    AssemblyClassLoader acl         = classLoader as AssemblyClassLoader;
                    if (acl == null || acl.GetAssembly(tw) != typeof(object).Assembly)
                    {
                        java.lang.ClassLoader javaClassLoader = classLoader.GetJavaClassLoader();
                        if (javaClassLoader != null)
                        {
                            return(javaClassLoader);
                        }
                    }
                }
            }
        }
        return(null);
    }
Пример #2
0
    private static string GetAssemblyName(TypeWrapper tw)
    {
        ClassLoaderWrapper  loader = tw.GetClassLoader();
        AssemblyClassLoader acl    = loader as AssemblyClassLoader;

        if (acl != null)
        {
            return(acl.GetAssembly(tw).FullName);
        }
        else
        {
            return(((GenericClassLoader)loader).GetName());
        }
    }