internal EventPipe(Plugin source, MethodInfo info, PipeEvent pipe) : base(source, info, info.IsStatic)
        {
            EventName   = pipe.EventName;
            pluginScope = pipe.PluginScope;

            this.info = info;
            Type      = typeof(void);

            if (info.ReturnType != Type)
            {
                PluginManager.Manager.Logger.Warn("PIPE_MANAGER", $"Pipe event {source} returns a value. This is bad practice.");
            }
        }
Exemple #2
0
        public PluginPipes(Plugin plugin)
        {
            Type pluginType          = plugin.GetType();
            const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;

            fields = new Dictionary <string, FieldPipe>();
            foreach (FieldInfo field in pluginType.GetFields(flags))
            {
                PipeField pipe = field.GetCustomAttribute <PipeField>();
                if (pipe != null)
                {
                    fields.Add(field.Name, Create <FieldPipe>(typeof(FieldPipe <>), field.FieldType, plugin, field, pipe));
                }
            }

            properties = new Dictionary <string, PropertyPipe>();
            foreach (PropertyInfo property in pluginType.GetProperties(flags))
            {
                PipeProperty pipe = property.GetCustomAttribute <PipeProperty>();
                if (pipe != null)
                {
                    properties.Add(property.Name, Create <PropertyPipe>(typeof(PropertyPipe <>), property.PropertyType, plugin, property, pipe));
                }
            }

            methods = new Dictionary <string, MethodPipe>();
            events  = new Dictionary <string, EventPipe>();
            foreach (MethodInfo method in pluginType.GetMethods(flags | BindingFlags.NonPublic))
            {
                if (method.IsPublic)
                {
                    PipeMethod pipeMethod = method.GetCustomAttribute <PipeMethod>();
                    if (pipeMethod != null)
                    {
                        methods.Add(method.Name, Create <MethodPipe>(typeof(MethodPipe <>), method.ReturnType, plugin, method));

                        continue;
                    }
                }

                PipeEvent pipeEvent = method.GetCustomAttribute <PipeEvent>();
                if (pipeEvent != null)
                {
                    events.Add(method.Name, new EventPipe(plugin, method, pipeEvent));
                }
            }
        }