internal PropertyPipe(Plugin source, PropertyInfo info, PipeProperty pipe) : base(source, info, info.GetMethod?.IsStatic ?? info.SetMethod.IsStatic)
        {
            Gettable = pipe.Gettable;
            Settable = pipe.Settable;

            this.info = info;

            Type     = info.PropertyType;
            Gettable = Gettable && info.GetMethod != null;
            Settable = Settable && info.SetMethod != null;

            if (!Gettable && !Settable)
            {
                PluginManager.Manager.Logger.Warn("PIPE_MANAGER", $"Pipe property {Name} in {Source.Details.id} has no accessable getter or setter. This is bad practice.");
            }
        }
Ejemplo n.º 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));
                }
            }
        }