using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; namespace CPF.Windows.Json { internal class BootTable { internal Dictionary DefaultSameTypes = new Dictionary(); internal List> DefaultImplementedInterfaces = new List>(); internal List> DefaultImplementedBaseType = new List>(); internal HashSet DefaultAvoidTypes; internal List ExpressionBuildTypes = new List(); public BootTable(BootTableTypeEnum bootTableTypeEnum) { Type normalBaseType = null; Type expressBaseTypes = null; switch (bootTableTypeEnum) { case BootTableTypeEnum.DeserializeResolve: normalBaseType = typeof(Deserialize.DefaultJsonResolve); expressBaseTypes = typeof(Deserialize.ExpressionJsonResolve); break; case BootTableTypeEnum.SerializerLogic: normalBaseType = typeof(Serializer.DefaultJsonFormatter); expressBaseTypes = typeof(Serializer.ExpressionJsonFormatter); break; } var normalMethods = new List(); foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { if (type.BaseType == expressBaseTypes) ExpressionBuildTypes.Add(type); if (type.BaseType == normalBaseType) normalMethods.AddRange(type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic)); } foreach (var item in normalMethods) { var atr = item.GetCustomAttribute(); if (atr == null) continue; Type t = null; switch (bootTableTypeEnum) { case BootTableTypeEnum.DeserializeResolve: t = item.ReturnType; break; case BootTableTypeEnum.SerializerLogic: t = item.GetParameters()[0].ParameterType; break; } switch (atr._Type) { case FuncType.SameType: DefaultSameTypes.Add(t, item); break; case FuncType.BaseType: DefaultImplementedBaseType.Add(new KeyValuePair(t, new MethodInfoOrder(item, atr._Priority))); break; case FuncType.Interface: DefaultImplementedInterfaces.Add(new KeyValuePair(t, new MethodInfoOrder(item, atr._Priority))); break; } } DefaultImplementedBaseType = DefaultImplementedBaseType.OrderBy(e => e.Value.Priority).ToList(); DefaultImplementedInterfaces = DefaultImplementedInterfaces.OrderBy(e => e.Value.Priority).ToList(); DefaultAvoidTypes = new HashSet() { typeof(Process), typeof(Delegate), typeof(Thread), typeof(Task) }; } } }