public static BasicGameCommand GetBasicGameCommand(this ISimpleGame payLoad, string commandName)
        {
            string functionName = $"Can{commandName}";

            functionName = functionName.Replace("Async", "");
            MethodInfo?method = payLoad.GetPrivateMethod(commandName);

            if (method == null)
            {
                Type type = payLoad.GetType();
                throw new BasicBlankException($"Method with the name of {commandName} was not found  Type was {type.Name}");
            }
            MethodInfo?      fun = payLoad.GetPrivateMethod(functionName);
            BasicGameCommand output;

            if (fun != null)
            {
                output = new BasicGameCommand(payLoad, method, canExecuteM: fun, payLoad.CommandContainer);
            }
            else
            {
                PropertyInfo?pp = payLoad.GetPrivateProperty(functionName);
                output = new BasicGameCommand(payLoad, method, canExecute: pp, payLoad.CommandContainer);
            }
            return(output);
        }
Esempio n. 2
0
        private static ICommand GetCommand(object viewModel, MethodInfo method, MethodInfo?validateM, PropertyInfo?foundProperty)
        {
            var item = method.GetCustomAttribute <CommandAttribute>();

            if (item == null)
            {
                throw new BasicBlankException("Was not even a custom command.  Rethink");
            }
            ICommand?output;

            if (!(viewModel is IBlankGameVM blank))
            {
                throw new BasicBlankException("This is not a blank game view model.  Rethink");
            }
            if (blank.CommandContainer == null)
            {
                throw new BasicBlankException("The command container for command not there.  Rethink");
            }
            switch (item.Category)
            {
            case EnumCommandCategory.Plain:
                if (foundProperty == null && validateM != null)
                {
                    output = new PlainCommand(viewModel, method, validateM, blank.CommandContainer);
                }
                else
                {
                    output = new PlainCommand(viewModel, method, foundProperty !, blank.CommandContainer);
                }
                break;

            case EnumCommandCategory.Game:
                if (!(viewModel is IBasicEnableProcess basics))
                {
                    throw new BasicBlankException("You need to implement the IEnableAlways in order to use out of turn command.  Rethink");
                }
                if (foundProperty == null && validateM != null)
                {
                    output = new BasicGameCommand(basics, method, validateM, blank.CommandContainer);
                }
                else
                {
                    output = new BasicGameCommand(basics, method, foundProperty !, blank.CommandContainer);
                }
                break;

            case EnumCommandCategory.Limited:
                if (!(viewModel is IBasicEnableProcess basics2))
                {
                    throw new BasicBlankException("You need to implement the IEnableAlways in order to use out of turn command.  Rethink");
                }
                if (foundProperty == null && validateM != null)
                {
                    output = new LimitedGameCommand(basics2, method, validateM, blank.CommandContainer);
                }
                else
                {
                    output = new LimitedGameCommand(basics2, method, foundProperty !, blank.CommandContainer);
                }
                break;

            case EnumCommandCategory.OutOfTurn:

                if (!(viewModel is IEnableAlways enables))
                {
                    throw new BasicBlankException("You need to implement the IEnableAlways in order to use out of turn command.  Rethink");
                }

                output = new OutOfTurnCommand(enables, method, blank.CommandContainer);
                break;

            case EnumCommandCategory.Open:
                if (foundProperty == null && validateM != null)
                {
                    output = new OpenCommand(viewModel, method, validateM, blank.CommandContainer);
                }
                else
                {
                    output = new OpenCommand(viewModel, method, foundProperty !, blank.CommandContainer);
                }
                break;

            case EnumCommandCategory.Control:
                if (!(viewModel is IControlObservable control))
                {
                    throw new BasicBlankException("You need to implement the IControlVM in order to use control command.  Rethink");
                }
                output = new ControlCommand(control, method, blank.CommandContainer);
                break;

            case EnumCommandCategory.Old:
                if (foundProperty == null && validateM != null)
                {
                    output = new ReflectiveCommand(viewModel, method, validateM);
                }
                else
                {
                    output = new ReflectiveCommand(viewModel, method, foundProperty !);
                }
                break;

            default:
                throw new BasicBlankException("Not supported");
            }
            if (output == null)
            {
                throw new BasicBlankException("No command.   Rethink");
            }
            return(output);
        }