| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 | using InABox.Core;using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Text;namespace Comal.TaskScheduler.Shared{    public static class SchedulePluginFactory    {        private static Dictionary<String, ISchedulePlugin> cache = new Dictionary<string, ISchedulePlugin>();        public static ISchedulePlugin? GetPlugin(String scheduleclass)        {            if (String.IsNullOrWhiteSpace(scheduleclass))                return null;            if (cache.ContainsKey(scheduleclass))                return cache[scheduleclass];            if (!CoreUtils.TryGetEntity(scheduleclass, out var type))                return null;            Type defType = typeof(SchedulePlugin<>).MakeGenericType(type);            Type? subType = CoreUtils.TypeList(                new Assembly[] { typeof(SchedulePluginFactory).Assembly },                myType =>                myType.IsClass                && !myType.IsAbstract                && !myType.IsGenericType                && myType.IsSubclassOf(defType)            ).FirstOrDefault();            if(subType == null)            {                return null;            }            ISchedulePlugin result = (ISchedulePlugin)Activator.CreateInstance(subType)!;            cache[scheduleclass] = result;            return result;        }    }}
 |