using Bro.Common.Helper; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Configuration; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace Bro.Common.Factory { public static class FactoryHelper { private static List types = new List(); public static List TYPES { get { if (types.Count <= 0) { var dllFiles = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).GetFiles("*.dll").Select(u => u.FullName).ToList(); dllFiles.ForEach(f => { try { Assembly assm = Assembly.LoadFrom(f); if (assm != null) { assm.GetTypes().ToList().ForEach(t => { DeviceAttribute attr = t.GetCustomAttribute(); if (attr != null) { types.Add(t); //if (attr.AttrType == EnumHelper.DeviceAttributeType.Device) //{ // DEVICE_TYPE_NAMES.Add(attr.TypeCode); // DEVICE_DICT[attr.TypeCode] = t; //} } }); } } catch (Exception) { } }); } return types; } } //private static Dictionary device_dict = new Dictionary(); //public static Dictionary DEVICE_DICT //{ // get // { // if (device_dict.Count < 0) // { // } // return device_dict; // } //} //private static List device_type_names = new List(); //public static List DEVICE_TYPE_NAMES //{ // get // { // if (device_type_names.Count < 0) // { // } // return device_type_names; // } //} public static Type GetTypeByAtrributeTypeName(string attrTypeName, EnumHelper.DeviceAttributeType attrType) { Type type = TYPES.FirstOrDefault(t => { DeviceAttribute attr = t.GetCustomAttribute(); return attr != null && attr.TypeCode == attrTypeName && attr.AttrType == attrType; }); return type; } } }