public IntellectSecurityProxy() { byte[] assembly = (byte[])AppDomain.CurrentDomain.GetData("Intellect"); var loadedAssembly = Assembly.Load(assembly); var types = loadedAssembly.GetTypes(); var type = types.First(x => x.GetInterface("IBeingInterface") != null); _intellect = (IBeingInterface)loadedAssembly.CreateInstance(type.FullName); }
public static List <IBeingInterface> AddBeing(byte[] dll) { List <IBeingInterface> objects = new List <IBeingInterface>(); Assembly assembly = Assembly.Load(dll); string iMyInterfaceName = typeof(IBeingInterface).ToString(); TypeDelegator[] defaultConstructorParametersTypes = new TypeDelegator[0]; object[] defaultConstructorParameters = new object[0]; IBeingInterface iAI = null; foreach (Type type in assembly.GetTypes()) { if (type.GetInterface(iMyInterfaceName) != null) { ConstructorInfo defaultConstructor = type.GetConstructor(defaultConstructorParametersTypes); object instance = defaultConstructor.Invoke(defaultConstructorParameters); iAI = (IBeingInterface)instance; //Достаём таки нужный интерфейс // objects.Add(iAI); } } return(objects); }
public IntellectDomainProxy(byte[] assembly) { _domain.SetData("Intellect", assembly); var asms = AppDomain.CurrentDomain.GetAssemblies(); var s1 = AppDomain.CurrentDomain.BaseDirectory; var s2 = _domain.BaseDirectory; try { foreach (var asm in asms) { if (asm.FullName.Contains("WarSpot.Contracts.Intellect")) { _domain.CreateInstanceFrom(asm.Location, typeof(BeingCharacteristics).FullName); } } _reference = (IBeingInterface)_domain.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location, typeof(IntellectSecurityProxy).FullName); } catch (Exception e) { throw; } }
public void Unload() { _reference = null; AppDomain.Unload(_domain); }