Beispiel #1
0
        public static string[] GetAssembliesWithType(string[] paths, Type type)
        {
            TypeCheckAppDomain instance = CreateInstance();

            string[] files = instance.InternalGetAssembliesWithType(paths, type);

            AppDomain.Unload(instance._appdomain);

            return(files);
        }
Beispiel #2
0
        private static IEnumerable <Type> GetTypes()
        {
            Type icondition = typeof(ICondition);

            List <Type> types = new List <Type>();

            foreach (string file in TypeCheckAppDomain.GetAssembliesWithType(new[] { Program.Location, Path.Combine(Program.Location, "plugins"), Path.Combine(Program.Location, "plugin"), Path.Combine(Program.Location, "addons"), Path.Combine(Program.Location, "addon") }, icondition))
            {
                Assembly asm = Assembly.LoadFile(file);

                foreach (Type t in asm.GetTypes().Where(t => t.IsClass && !t.IsAbstract && icondition.IsAssignableFrom(t)))
                {
                    types.Add(t);
                }
            }

            return(types);
        }
Beispiel #3
0
        private static TypeCheckAppDomain CreateInstance()
        {
            string id = $"MultiDeviceKeybinds_{++_counter}";
            string shadowCopyFolderName = $"{id}_ShadowCopy";
            string shadowCopyFolderPath = CreateShadowCopyFolder(shadowCopyFolderName);

            AppDomainSetup setup = new AppDomainSetup
            {
                CachePath = shadowCopyFolderPath
            };

            string    domainName = $"{id}_AppDomain";
            AppDomain domain     = AppDomain.CreateDomain(domainName, AppDomain.CurrentDomain.Evidence, setup);

            Type typeToCreate = typeof(TypeCheckAppDomain);

            TypeCheckAppDomain instance = (TypeCheckAppDomain)domain.CreateInstanceAndUnwrap(typeToCreate.Assembly.FullName, typeToCreate.FullName, false, BindingFlags.CreateInstance, null, new object[] { }, CultureInfo.InvariantCulture, null);

            return(instance);
        }