Beispiel #1
0
        private void SortList()
        {
            Functions.Sort((f1, f2) =>
            {
                // The first function in the list should be the most specialized.
                // If the execute the command we will iterate through the list from the beginning
                // and choose the first matching function.

                // Sort out special arguments
                // and remove the nullable wrapper
                var params1 = (from p in f1.CommandParameter
                               where p.kind.IsNormal()
                               select FunctionCommand.UnwrapType(p.type)).ToList();

                var params2 = (from p in f2.CommandParameter
                               where p.kind.IsNormal()
                               select FunctionCommand.UnwrapType(p.type)).ToList();

                for (int i = 0; i < params1.Count; i++)
                {
                    // Prefer functions with higher parameter count
                    if (i >= params2.Count)
                    {
                        return(-1);
                    }
                    int i1 = Array.IndexOf(XCommandSystem.TypeOrder, params1[i]);
                    if (i1 == -1)
                    {
                        i1 = XCommandSystem.TypeOrder.Length;
                    }
                    int i2 = Array.IndexOf(XCommandSystem.TypeOrder, params2[i]);
                    if (i2 == -1)
                    {
                        i2 = XCommandSystem.TypeOrder.Length;
                    }
                    // Prefer lower argument
                    if (i1 < i2)
                    {
                        return(-1);
                    }
                    if (i1 > i2)
                    {
                        return(1);
                    }
                }
                if (params2.Count > params1.Count)
                {
                    return(1);
                }

                return(0);
            });
        }
        public virtual object Execute(ExecutionInformation info, IReadOnlyList <ICommand> arguments, IReadOnlyList <Type> returnTypes)
        {
            var filterLazy = info.GetFilterLazy();

            foreach (var type in returnTypes)
            {
                try
                {
                    var result = FunctionCommand.ConvertParam(Content, type, filterLazy);
                    Log.Debug("Converting command result {0} to {1} returns {2}", Content, type, result);

                    return(ResultHelper.ToResult(type, result));
                }
                catch (Exception ex)
                {
                    Log.Debug(ex, "Converting command result {0} to {1} failed", Content, type);
                }
            }
            throw new CommandException(strings.error_cmd_no_matching_overload, CommandExceptionReason.NoReturnMatch);
        }
Beispiel #3
0
 public void RemoveCommand(FunctionCommand command) => Functions.Remove(command);
Beispiel #4
0
 public void AddCommand(FunctionCommand command)
 {
     Functions.Add(command);
     SortList();
 }
Beispiel #5
0
 public bool RemoveCommand(FunctionCommand command) => Functions.Remove(command);