public void Load() { UiTypes = new Dictionary <UIType, IUIFactory>(); Type[] types = DllHelper.GetHotfixTypes(); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(UIFactoryAttribute), false); if (attrs.Length == 0) { continue; } UIFactoryAttribute attribute = attrs[0] as UIFactoryAttribute; if (UiTypes.ContainsKey((UIType)attribute.Type)) { Log.Debug($"已经存在同类UI Factory: {attribute.Type}"); throw new Exception($"已经存在同类UI Factory: {attribute.Type}"); } object o = Activator.CreateInstance(type); IUIFactory factory = o as IUIFactory; if (factory == null) { Log.Error($"{o.GetType().FullName} 没有继承 IUIFactory"); continue; } this.UiTypes.Add((UIType)attribute.Type, factory); } }
public void Load() { this.UiTypes = new Dictionary <int, IUIFactory>(); Type[] types = DllHelper.GetHotfixTypes(); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(UIFactoryAttribute), false); if (attrs.Length == 0) { continue; } UIFactoryAttribute attribute = attrs[0] as UIFactoryAttribute; if (this.UiTypes.ContainsKey(attribute.Type)) { throw new Exception($"已经存在同类UI Factory: {attribute.Type}"); } IUIFactory iuiFactory = new IILUIFactoryMethod(type); this.UiTypes.Add(attribute.Type, iuiFactory); } }