Beispiel #1
0
 private void InitializeComponent(Component component)
 {
     if (component is IModHandler)
     {
         IModHandler modHandler = component as IModHandler;
         modHandler.OnLoaded(this);
     }
 }
Beispiel #2
0
        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);
                            }
                        }
                    }
                }
            }
        }