private void InitializeComponent(Component component) { if (component is IModHandler) { IModHandler modHandler = component as IModHandler; modHandler.OnLoaded(this); } }
private static void RegisterModHandlers() { // Use reflection to get all of IModHandler implementations. var classes = Assembly.GetCallingAssembly().GetTypes() .Where(p => typeof(IModHandler).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract).ToArray(); foreach (var type in classes) { IModHandler instance = Activator.CreateInstance(type) as IModHandler; if (instance == null) { throw new NullReferenceException("Unable to activate instance of type: " + type); } _modHandlers.Add(instance.ModTypeID, instance); } }
private static void InitializeModHandlers(ContentHandler contentHandler) { foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Type type in assembly.GetTypes()) { if (typeof(IModHandler).IsAssignableFrom(type)) { if (type.IsAbstract) { continue; } if (!type.IsClass) { continue; } if (type.IsSubclassOf(typeof(Component))) { foreach (Component component in GetComponents(type)) { ((IModHandler)component).OnLoaded(contentHandler); } continue; } try { IModHandler loadHandler = (IModHandler)Activator.CreateInstance(type); loadHandler.OnLoaded(contentHandler); } catch (Exception e) { if (e is MissingMethodException) { LogUtility.LogWarning(e.Message); } } } } } }