コード例 #1
0
ファイル: DataManager.cs プロジェクト: AlwaysHC/ManyQueues
        public void LoadDataReaders <TData>(string name)
        {
            Log.Log(MethodBase.GetCurrentMethod() !.Name, $"{name} {typeof(TData)}");

            Type TO = typeof(IDataReader <TData>);

            foreach (Assembly Ass in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (Type Type in Ass.GetTypes().Where(t => t.IsClass && TO.IsAssignableFrom(t)))
                {
                    MethodInfo?MethodAutoLoad = Type.GetMethod(nameof(IDataReader.AutoLoad));
                    if ((bool)(MethodAutoLoad?.Invoke(null, null) ?? true))
                    {
                        IDataReader <TData>?Subscriber = Type.GetConstructors()[0].GetParameters().Length == 1
                            ? (IDataReader <TData>?)Activator.CreateInstance(Type, this)
                            : (IDataReader <TData>?)Activator.CreateInstance(Type);
                        if (Subscriber != null)
                        {
                            SubscribeDataReader <TData>(name, Subscriber);
                        }
                    }
                }
            }

            Log.Log(MethodBase.GetCurrentMethod() !.Name, $"{name} {typeof(TData)} Loaded");
        }
コード例 #2
0
        protected IEnumerable <Type> GetAPICommandClasses()
        {
            if (API_type != null)
            {
                Assembly[] asses = AppDomain.CurrentDomain.GetAssemblies();

                List <Assembly> GoodLooking = new List <Assembly>();
                foreach (Assembly Ass in asses)
                {
                    if (Ass.FullName.StartsWith("BetterSecondbot") == true)
                    {
                        GoodLooking.Add(Ass);
                    }
                    else if (Ass.FullName.StartsWith("Core") == true)
                    {
                        GoodLooking.Add(Ass);
                    }
                    else if (Ass.FullName.StartsWith("Shared") == true)
                    {
                        GoodLooking.Add(Ass);
                    }
                }

                List <Type> reply = new List <Type>();
                foreach (Assembly Ass in GoodLooking)
                {
                    foreach (Type ClassType in Ass.GetTypes())
                    {
                        if (ClassType.IsSubclassOf(API_type) == true)
                        {
                            reply.Add(ClassType);
                        }
                    }
                }
                return(reply);
            }
            else
            {
                LogFormater.Crit(this.GetType() + " Attempted to call GetSubTypes without setting API_TYPE first!");
            }
            return(null);
        }