Exemplo n.º 1
0
        public MarshalByRefObject CreateInstance(RemoteClass rclass, params object[] args)
        {
            if (LoadedAssemblies.TryGetValue(rclass.AssemblyName, out Assembly assembly))
            {
                var type         = assembly.GetType(rclass.Namespace + "." + rclass.TypeNme);
                var constructors = type.GetConstructors().Where(c => c.GetParameters().Length == args.Length);
                foreach (var constructor in constructors)
                {
                    bool match      = true;
                    var  paramtypes = constructor.GetParameters().Select(p => p.ParameterType).ToArray();
                    for (int i = 0; i < paramtypes.Length; ++i)
                    {
                        if (!IsAssignable(paramtypes[i], args[i].GetType()))
                        {
                            match = false;
                            break;
                        }
                    }
                    if (match)
                    {
                        return((MarshalByRefObject)constructor.Invoke(args));
                    }
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        public void Unload()
        {
            if (Domain != null)
            {
                Unloaded?.Invoke(this, Domain);

                AppDomain.Unload(Domain);
                AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
                Domain = null;
            }

            Unloaded = null;

            Assemblies.Clear();
            Classes = new RemoteClass[0];
        }