Ejemplo n.º 1
0
        private FindMethodResult FindMatchingBase(ITypeDefinition type, IMethodDefinition method, out IMethodDefinition resultMethod)
        {
            resultMethod = null;
            if (type == null || method.IsConstructor)
            {
                return(FindMethodResult.NotFound);
            }

            bool foundMethodWithDifferentReturnType = false;

            foreach (var baseType in type.GetAllBaseTypes())
            {
                FindMethodResult found = FindMethodInCollection(method, baseType.Methods, out resultMethod, false);
                if (found == FindMethodResult.Found)
                {
                    return(found);
                }
                if (found == FindMethodResult.ReturnTypeChanged)
                {
                    foundMethodWithDifferentReturnType = true;
                }
            }
            if (foundMethodWithDifferentReturnType)
            {
                return(FindMethodResult.ReturnTypeChanged);
            }

            return(FindMethodResult.NotFound);
        }
Ejemplo n.º 2
0
        public virtual async Task <Result> TryExecute(SocketUserMessage e, int depth, params object[] arguments)
        {
            string executionError  = AllowExecution(e);
            string executionPrefix = "Failed to execute command " + command;

            if (executionError == "")
            {
                if (arguments.Length == 1)
                {
                    string stringArg = arguments [0].ToString();
                    if (stringArg [0] == '(')
                    {
                        arguments = Utility.SplitArgs(GetParenthesesArgs(stringArg)).ToArray();
                    }
                }

                arguments = (await ConvertChainCommandsToObjects(e, arguments.ToList(), depth)).ToArray();
                FindMethodResult result = await FindMethod(arguments);

                if (result != null)
                {
                    try {
                        result.parameters.Insert(0, e);
                        Result task = await(result.method.Invoke(this, result.parameters.ToArray()) as Task <Result>);
                        AddToCallstack(e.Id, new Callstack.Item(this, result.parameters.GetRange(1, result.parameters.Count - 1).Select(x => x.ToString()).ToList(), task.message, task.value));
                        return(task);
                    } catch (Exception exc) {
                        Logging.Log(exc);
                    }
                }
                else
                {
                    Program.messageControl.SendMessage(e, $"{executionPrefix}: \n\tNo suitable command overload found.", allowInMain);
                }
            }
            else
            {
                Program.messageControl.SendMessage(e, $"{executionPrefix}: Failed to execute: {executionError}", allowInMain);
            }
            return(null);
        }