public int Execute(CommandLineContext context, BindResult bindResult)
        {
            var arguments = ReflectionHelper.BindParameters(Method, context, bindResult);

            var result = Method.Invoke(bindResult.Target, arguments);

            if (Method.ReturnType == typeof(int))
            {
                return((int)result);
            }

            return(0);
        }
Esempio n. 2
0
        public async Task <int> ExecuteAsync(CommandLineContext context, BindResult bindResult)
        {
            var arguments = ReflectionHelper.BindParameters(Method, context, bindResult);

            var result = (Task)Method.Invoke(bindResult.Target, arguments);

            if (result is Task <int> intResult)
            {
                return(await intResult);
            }

            await result;

            return(0);
        }
        private static int HandleValidationError <TApp>(IConsole console, BindContext bindResult)
        {
            var method = typeof(TApp).GetTypeInfo().GetMethod("OnValidationError", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

            if (method == null)
            {
                return(bindResult.App.DefaultValidationErrorHandler(bindResult.ValidationResult));
            }

            var arguments = ReflectionHelper.BindParameters(method, console, bindResult);
            var result    = method.Invoke(bindResult.Target, arguments);

            if (method.ReturnType == typeof(int))
            {
                return((int)result);
            }

            return(1);
        }
        private static int HandleValidationError(CommandLineContext context, BindResult bindResult)
        {
            const BindingFlags MethodFlags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

            var method = bindResult.Target
                         .GetType()
                         .GetTypeInfo()
                         .GetMethod("OnValidationError", MethodFlags);

            if (method == null)
            {
                return(bindResult.Command.DefaultValidationErrorHandler(bindResult.ValidationResult));
            }

            var arguments = ReflectionHelper.BindParameters(method, context, bindResult);
            var result    = method.Invoke(bindResult.Target, arguments);

            if (method.ReturnType == typeof(int))
            {
                return((int)result);
            }

            return(ValidationErrorExitCode);
        }