private ITypeParser GetTypeParser(CommandContext context, IParameter param)
        {
            var typeParserType = param.TypeParserType;

            if (typeParserType.HasContent())
            {
                var typeParser = context.CommandServices.GetService(typeParserType) as ITypeParser;

                if (typeParser.HasNoContent())
                {
                    typeParser = ActivatorUtilities.CreateInstance(context.CommandServices, typeParserType) as ITypeParser;

                    MiddlewareUtils.RegisterForDispose(typeParser, context);
                }

                return(typeParser);
            }

            var typeParserProvider = context.CommandServices.GetRequiredService <ITypeParserProvider>();

            var parameterType = param.IsParams
                ? param.ParameterInfo.ParameterType.GetElementType()
                : param.ParameterInfo.ParameterType;

            return(typeParserProvider.GetTypeParser(parameterType));
        }
        private async Task <IArgumentParserResult> ParseCommandAsync(CommandContext context, ICommand command, string rawArgs)
        {
            var provider = context.CommandServices;

            IArgumentParser argumentParser;
            var             argumentParserType = command.GetArgumentParserType();

            if (argumentParserType.HasContent())
            {
                argumentParser = provider.GetService(argumentParserType) as IArgumentParser;

                if (argumentParser.HasNoContent())
                {
                    argumentParser = ActivatorUtilities.CreateInstance(provider, argumentParserType) as IArgumentParser;

                    MiddlewareUtils.RegisterForDispose(argumentParser, context);
                }
            }
            else
            {
                argumentParser = provider.GetRequiredService <IArgumentParser>();
            }


            return(await argumentParser.ParseAsync(context, command, rawArgs));
        }
Example #3
0
        private object GetModule(CommandContext context, ICommand command)
        {
            var module = command.Module.Invoker.CreateInstance(context.CommandServices);

            MiddlewareUtils.RegisterForDispose(module, context);

            return(module);
        }