コード例 #1
0
        private bool Execute(FunctionSyncro syncro, Point point, object obj)
        {
            if (syncro != null)
            {
                Type   type          = syncro.GetFunction().GetParameterType(0);
                object converted_obj = obj.ConvertEX(type);

                if (converted_obj != null)
                {
                    if (syncro.GetFunction().CanParametersHold(type))
                    {
                        syncro.Execute(new object[] { converted_obj });
                        return(true);
                    }

                    if (syncro.GetFunction().CanParametersHold(type, typeof(Point)))
                    {
                        syncro.Execute(new object[] { converted_obj, point });
                        return(true);
                    }

                    throw new UnexpectedSignatureException(syncro.GetFunction().GetParameterTypes());
                }
            }

            return(false);
        }
コード例 #2
0
        static public MouseEventHandler GetMouseEventHandler(this FunctionSyncro item, Predicate <MouseEventArgs> predicate)
        {
            if (item.GetFunction().HasNoParameters())
            {
                return(delegate(object sender, MouseEventArgs e) {
                    if (predicate(e))
                    {
                        item.Execute();
                    }
                });
            }

            if (item.GetFunction().CanParametersHold <object, MouseEventArgs>())
            {
                return(delegate(object sender, MouseEventArgs e) {
                    if (predicate(e))
                    {
                        item.Execute(new object[] { sender, e });
                    }
                });
            }

            if (item.GetFunction().CanParametersHold <MouseEventArgs>())
            {
                return(delegate(object sender, MouseEventArgs e) {
                    if (predicate(e))
                    {
                        item.Execute(new object[] { e });
                    }
                });
            }

            throw new UnexpectedSignatureException(item.GetFunction().GetParameterTypes());
        }
コード例 #3
0
        static public ICommand GetCommand(this FunctionSyncro item)
        {
            if (item.GetFunction().HasNoParameters())
            {
                return(new ProcessCommand(delegate(object obj) {
                    item.Execute();
                }));
            }

            if (item.GetFunction().CanParametersHold <object>())
            {
                return(new ProcessCommand(delegate(object obj) {
                    item.Execute(new object[] { obj });
                }));
            }

            throw new UnexpectedSignatureException(item.GetFunction().GetParameterTypes());
        }
コード例 #4
0
        static public EventHandler <T> GetRoutedEventHandler <T>(this FunctionSyncro item, Predicate <T> predicate) where T : RoutedEventArgs
        {
            if (item.GetFunction().HasNoParameters())
            {
                return(delegate(object sender, T e) {
                    if (predicate(e))
                    {
                        item.Execute();
                        e.Handled = true;
                    }
                });
            }

            if (item.GetFunction().GetNumberParameters() == 1)
            {
                return(delegate(object sender, T e) {
                    if (predicate(e))
                    {
                        item.Execute(new object[] { e });
                        e.Handled = true;
                    }
                });
            }

            if (item.GetFunction().GetNumberParameters() == 2)
            {
                return(delegate(object sender, T e) {
                    if (predicate(e))
                    {
                        item.Execute(new object[] { sender, e });
                        e.Handled = true;
                    }
                });
            }

            throw new UnexpectedSignatureException(item.GetFunction().GetParameterTypes());
        }