Exemplo n.º 1
0
        public override IConnection Connect(IInputPlug inputPlug)
        {
            if (inputPlug is MethodPlug)
            {
                MethodPlug methodPlug = (MethodPlug)inputPlug;
                MethodInfo methodInfo = methodPlug.MethodInfo;

                Delegate connectionDelegate = null;

                try
                {
                    connectionDelegate = Delegate.CreateDelegate(eventInfo.EventHandlerType, inputPlug.Owner, methodInfo);
                    eventInfo.AddEventHandler(this.Owner, connectionDelegate);
                }
                catch (System.Exception)
                {
                    return(null);
                }

                // Create connection.
                EventMethodConnection connection = new EventMethodConnection(this, inputPlug, connectionDelegate);

                if (!inputPlug.OnConnection(connection))
                {
                    // Disconnect.
                    connection.Dispose();
                    return(null);
                }
                this.connections.Add(connection);
                return(connection);
            }
            return(null);
        }
Exemplo n.º 2
0
        public override bool IsCompatible(IInputPlug inputPlug)
        {
            MethodPlug methodPlug = inputPlug as MethodPlug;

            if (methodPlug != null)
            {
                if (Equals(eventInfo.GetRaiseMethod(), methodPlug.MethodInfo))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        public static MethodPlug[] Enumerate(IActor actor)
        {
            List <MethodPlug> list = new List <MethodPlug>();

            foreach (MethodInfo m in actor.GetType().GetMethods())
            {
                MethodPlug methodPlug = Create(m, actor);
                if (methodPlug != null)
                {
                    list.Add(methodPlug);
                }
            }

            return(list.ToArray());
        }