• AppDomain.Unload_MarshalByRefObject


            internal string GetClassInfo(string assemblyName, string className, string strField)
            {
                string ret = strField;
                if (!String.IsNullOrEmpty(assemblyName) && !String.IsNullOrEmpty(className))
                {
                    string callingDomainName = AppDomain.CurrentDomain.FriendlyName;//Thread.GetDomain().FriendlyName;                 
                    AppDomain ad = AppDomain.CreateDomain("Test Domain");
                    ProxyObject obj = (ProxyObject)ad.CreateInstanceFromAndUnwrap(callingDomainName, "XXNamespace.ProxyObject");
                    obj.LoadAssembly(assemblyName);
                    //obj.Invoke("TestDll.Class1", "Test", "It's a test");
                    ret = obj.GetClassInfo(className, strField);
                    AppDomain.Unload(ad);
                }
                return ret;
    
            }
    
    
    
        class ProxyObject : MarshalByRefObject
        {
            Assembly assembly = null;
            public void LoadAssembly(string assemblyName)
            {
                assembly = Assembly.LoadFile(assemblyName);
            }
    
            public string GetClassInfo(string className, string strField)
            {            
                string ret = strField;
                Type type = assembly.GetType(className, true, true);
                if (type != null)
                {
                    FieldInfo fieldinfo = type.GetField(strField, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static);
                    //return (String)fieldinfo.GetValue(assembly);
                    ret = (String)fieldinfo.GetValue(null);
                }
                return ret;
            }
    
            public bool Invoke(string fullClassName, string methodName, params Object[] args)
            {
                if (assembly == null)
                    return false;
                Type tp = assembly.GetType(fullClassName);
                if (tp == null)
                    return false;
                MethodInfo method = tp.GetMethod(methodName);
                if (method == null)
                    return false;
                Object obj = Activator.CreateInstance(tp);
                method.Invoke(obj, args);
                return true;
            }
        } 
  • 相关阅读:
    异常响应配置
    用户模块自定义
    数据库配置
    虚拟环境搭建
    SDK Manager failed to install 'java.exe' locking directory
    AndroidUI自动化测试工具-UIautomator
    Android自动化压力测试快速入门教程(图解)——MonkeyRunner
    adb 常用命令
    Android压力测试快速入门教程(图解)——Monkey工具
    测试用例的优先级别划分
  • 原文地址:https://www.cnblogs.com/sky20080101/p/6600882.html
Copyright © 2020-2023  润新知