示例#1
0
        internal static bool LoadPluginsFromAssembly(Assembly assembly)
        {
            Type[] typesFromAsm = assembly.GetTypes();

            DPluginDefinition definition = null;

            bool foundPlugin = false;

            foreach (Type type in typesFromAsm)
            {
                Attribute attribute = type.GetCustomAttribute(typeof(DPluginInformation), true);

                if (attribute != null)
                {
                    DPluginInformation pluginInformation = (DPluginInformation)attribute;
                    if (type.BaseType == typeof(DPlugin))
                    {
                        // Valid DAE Plugin!

                        foundPlugin = true;

                        definition = new DPluginDefinition(pluginInformation, type);

                        Logger.Log($"Loaded plugin from assembly '{assembly.FullName}':\n\tName: {pluginInformation.name}\n\tAuthor: {pluginInformation.author}\n\tDescription: {pluginInformation.description}");

                        break;
                    }
                }
            }

            if (foundPlugin && definition != null)
            {
                foreach (Type type in typesFromAsm)
                {
                    Attribute attribute = type.GetCustomAttribute(typeof(DCustomComponent), true);

                    if (attribute != null)
                    {
                        DCustomComponent customComponent = (DCustomComponent)attribute;
                        if (type.IsSubclassOf(typeof(Component)))
                        {
                            DCustomComponentDefinition componentDefinition = new DCustomComponentDefinition(customComponent, type);

                            definition.customComponents.Add(componentDefinition);

                            Logger.Log($"Loaded custom component from assembly '{assembly.FullName}':\n\tActual Name: {customComponent.name}\n\tUsable Name: {definition.information.name}.{customComponent.name}");
                        }
                    }
                }
            }

            if (definition != null)
            {
                definitions.Add(definition);

                return(true);
            }

            return(false);
        }
示例#2
0
 public DPluginDefinition(DPluginInformation information, Type plugin)
 {
     this.information = information;
     this.plugin      = plugin;
 }