/// <summary>
        /// Builds an argument list for the target <paramref name="method"/> from
        /// services embedded inside the <paramref name="container"/> instance.
        /// </summary>
        /// <param name="resolver">The <see cref="IArgumentResolver"/> instance that will determine the method arguments.</param>
        /// <param name="method">The target method.</param>
        /// <param name="container">The container that will provide the method arguments.</param>
        /// <param name="additionalArguments">The additional arguments that will be passed to the target method.</param>
        /// <returns>An array of objects to be used with the target method.</returns>
        public static object[] ResolveFrom(this IArgumentResolver resolver, MethodBase method,
                                           IServiceContainer container, params object[] additionalArguments)
        {
            var parameterTypes = from p in method.GetParameters()
                                 select p.ParameterType;

            return(resolver.ResolveFrom(parameterTypes, container, additionalArguments));
        }
示例#2
0
        /// <summary>
        /// Builds an argument list for the target <paramref name="method"/> from
        /// services embedded inside the <paramref name="container"/> instance.
        /// </summary>
        /// <param name="resolver">The <see cref="IArgumentResolver"/> instance that will determine the method arguments.</param>
        /// <param name="method">The target method.</param>
        /// <param name="container">The container that will provide the method arguments.</param>
        /// <param name="additionalArguments">The additional arguments that will be passed to the target method.</param>
        /// <returns>An array of objects to be used with the target method.</returns>
        public static object[] ResolveFrom(this IArgumentResolver resolver, MethodBase method,
                                           IServiceContainer container, params object[] additionalArguments)
        {
            IEnumerable <INamedType> parameterTypes = from p in method.GetParameters()
                                                      select new NamedType(p) as INamedType;

            return(resolver.ResolveFrom(parameterTypes, container, additionalArguments));
        }
示例#3
0
        /// <summary>
        /// Injects services from the <paramref name="container"/> into the target <see cref="MethodInfo"/> instance.
        /// </summary>
        /// <param name="target">The target object.</param>
        /// <param name="method">The <see cref="MethodInfo"/> instance that will store the service instance.</param>
        /// <param name="resolver">The <see cref="IArgumentResolver"/> that will determine which arguments will be assigned to the target member.</param>
        /// <param name="additionalArguments">The additional arguments that were passed to the <see cref="IServiceRequestResult"/> during the instantiation process.</param>
        /// <param name="container">The container that will provide the service instances.</param>
        protected override void Inject(object target, MethodInfo method,
                                       IArgumentResolver resolver, IServiceContainer container, object[] additionalArguments)
        {
            var parameterTypes = from p in method.GetParameters()
                                 select p.ParameterType;

            var arguments = resolver.ResolveFrom(parameterTypes, container, additionalArguments);

            // Invoke the target method
            method.Invoke(target, arguments);
        }
示例#4
0
        /// <summary>
        /// Injects services from the <paramref name="container"/> into the target <see cref="MethodInfo"/> instance.
        /// </summary>
        /// <param name="target">The target object.</param>
        /// <param name="method">The <see cref="MethodInfo"/> instance that will store the service instance.</param>
        /// <param name="resolver">The <see cref="IArgumentResolver"/> that will determine which arguments will be assigned to the target member.</param>
        /// <param name="additionalArguments">The additional arguments that were passed to the <see cref="IServiceRequestResult"/> during the instantiation process.</param>
        /// <param name="container">The container that will provide the service instances.</param>
        protected override void Inject(object target, MethodInfo method,
                                       IArgumentResolver resolver, IServiceContainer container,
                                       object[] additionalArguments)
        {
            IEnumerable <INamedType> parameterTypes = from p in method.GetParameters()
                                                      select new NamedType(p) as INamedType;

            object[] arguments = resolver.ResolveFrom(parameterTypes, container, additionalArguments);

            // Invoke the target method
            method.Invoke(target, arguments);
        }
示例#5
0
        /// <summary>
        ///     Injects a field with values from a given container.
        /// </summary>
        /// <param name="target">The target object.</param>
        /// <param name="member">The <see cref="FieldInfo" /> instance that will store the service instance.</param>
        /// <param name="argumentResolver">
        ///     The <see cref="IArgumentResolver" /> that will determine which values will be assigned
        ///     to the target member.
        /// </param>
        /// <param name="additionalArguments">
        ///     The additional arguments that were passed to the <see cref="IServiceRequestResult" />
        ///     during the instantiation process. Note: This parameter will be ignored by this override.
        /// </param>
        /// <param name="container">The container that will provide the service instances.</param>
        protected override void Inject(object target, FieldInfo member, IArgumentResolver argumentResolver,
                                       IServiceContainer container, object[] additionalArguments)
        {
            // Get the field value from the container
            var fieldType   = new NamedType(member.FieldType);
            var fieldValues = argumentResolver.ResolveFrom(new[] { fieldType }, container);

            if (fieldValues == null || fieldValues.Length == 0)
            {
                return;
            }

            // Cast the field value to the target type
            var value = fieldValues[0];

            member.SetValue(target, value);
        }
        /// <summary>
        /// Injects services from the <paramref name="container"/> into the target <see cref="PropertyInfo"/> instance.
        /// </summary>
        /// <param name="target">The target object.</param>
        /// <param name="property">The <see cref="PropertyInfo"/> instance that will store the service instance.</param>
        /// <param name="resolver">The <see cref="IArgumentResolver"/> that will determine which arguments will be assigned to the target member.</param>
        /// <param name="additionalArguments">The additional arguments that were passed to the <see cref="IServiceRequestResult"/> during the instantiation process.</param>
        /// <param name="container">The container that will provide the service instances.</param>
        protected override void Inject(object target, PropertyInfo property,
                                       IArgumentResolver resolver, IServiceContainer container, object[] additionalArguments)
        {
            var setter = container.GetService <IPropertySetter>();

            if (setter == null)
            {
                return;
            }

            // Determine the property value
            var results       = resolver.ResolveFrom(new Type[] { property.PropertyType }, container);
            var propertyValue = results.FirstOrDefault();

            if (propertyValue == null)
            {
                return;
            }

            // Call the setter against the target property
            setter.Set(target, property, propertyValue);
        }
示例#7
0
 /// <inheritdoc/>
 public ListResolver(ILogger <CommandLineParser> logger, IArgumentResolver <TModel> resolver)
 {
     this.logger   = logger ?? throw new ArgumentNullException(nameof(logger));
     this.resolver = resolver ?? throw new ArgumentNullException(nameof(resolver));
 }
 public FunctionExpressionTreeBuilder(IArgumentResolver argResolver)
 {
     _argResolver = argResolver;
 }
 public NonGenericDiscoverableCommand(IArgumentResolver <NonGenericDiscoverableCommand> argResolver)
 {
     this.argResolver = argResolver;
 }
示例#10
0
 public CommandLineOption(CommandLineParserOptions parserOptions, object source, LambdaExpression selector, IArgumentResolver <TOption> argumentResolver, ILogger logger)
     : base(parserOptions, source, selector, argumentResolver, logger)
 {
     this.AllowMultipleValues = typeof(TOption).CanHaveMultipleValues();
 }
示例#11
0
 /// <summary>
 /// Initializes the class with the default services.
 /// </summary>
 /// <param name="container">The target service container.</param>
 public void Initialize(IServiceContainer container)
 {
     _argumentResolver  = container.GetService <IArgumentResolver>();
     _resolver          = container.GetService <IMemberResolver <ConstructorInfo> >();
     _constructorInvoke = container.GetService <IMethodInvoke <ConstructorInfo> >();
 }
示例#12
0
 /// <summary>
 /// Initializes the class with the default services.
 /// </summary>
 /// <param name="container">The target service container.</param>
 public void Initialize(IServiceContainer container)
 {
     _argumentResolver = container.GetService<IArgumentResolver>();
 }
 /// <summary>
 ///     Initializes the class with the default services.
 /// </summary>
 /// <param name="container">The target service container.</param>
 public void Initialize(IServiceContainer container)
 {
     _argumentResolver = container.GetService <IArgumentResolver>();
 }
示例#14
0
 /// <summary>
 /// Injects services from the <paramref name="container"/> into the target <paramref name="member"/> instance.
 /// </summary>
 /// <param name="target">The target object.</param>
 /// <param name="member">The <typeparamref name="TMember"/> instance that will store the service instance.</param>
 /// <param name="argumentResolver">The <see cref="IArgumentResolver"/> that will determine which arguments will be assigned to the target member.</param>
 /// <param name="additionalArguments">The additional arguments that were passed to the <see cref="IServiceRequestResult"/> during the instantiation process.</param>
 /// <param name="container">The container that will provide the service instances.</param>
 protected abstract void Inject(object target, TMember member, IArgumentResolver argumentResolver,
                                IServiceContainer container, object[] additionalArguments);