예제 #1
0
            public override ShortcutEntry CreateShortcutEntry(MethodInfo methodInfo)
            {
                var identifier = new Identifier(methodInfo, this);

                IEnumerable <KeyCombination> defaultCombination;

                KeyCombination keyCombination;

                if (KeyCombination.TryParseMenuItemBindingString(defaultKeyCombination, out keyCombination))
                {
                    defaultCombination = new[] { keyCombination }
                }
                ;
                else
                {
                    defaultCombination = Enumerable.Empty <KeyCombination>();
                }

                var type = ShortcutType.Action;
                //var type = this is ClutchShortcutAttribute ? ShortcutType.Clutch : ShortcutType.Action;
                var methodParams = methodInfo.GetParameters();
                Action <ShortcutArguments> action;

                if (methodParams.Length == 0)
                {
                    action = shortcutArgs =>
                    {
                        methodInfo.Invoke(null, k_EmptyReusableShortcutArgs);
                    };
                }
                else
                {
                    action = shortcutArgs =>
                    {
                        k_ReusableShortcutArgs[0].context = shortcutArgs.context;
                        k_ReusableShortcutArgs[0].state   = shortcutArgs.state;
                        methodInfo.Invoke(null, k_ReusableShortcutArgs);
                    };
                }

                return(new ShortcutEntry(identifier, defaultCombination, action, context, type));
            }