Ejemplo n.º 1
0
        public Expression GetExpression(
            IResolutionStrategy resolutionStrategy,
            TypeInformation typeInfo,
            ResolutionContext resolutionContext)
        {
            var args             = typeInfo.Type.GetGenericArguments();
            var tupleConstructor = typeInfo.Type.GetConstructor(args);
            var length           = args.Length;
            var expressions      = new Expression[length];

            for (var i = 0; i < length; i++)
            {
                var argumentInfo = typeInfo.CloneForType(args[i]);
                var expr         = resolutionStrategy.BuildExpressionForType(resolutionContext, argumentInfo);

                if (expr != null)
                {
                    expressions[i] = expr;
                }
                else
                {
                    return(null);
                }
            }

            return(tupleConstructor.MakeNew(expressions));
        }
Ejemplo n.º 2
0
        public Expression GetExpression(
            IResolutionStrategy resolutionStrategy,
            TypeInformation typeInfo,
            ResolutionContext resolutionContext)
        {
            var newTypeInfo = typeInfo.CloneForType(typeInfo.Type.GetEnumerableType());
            var expressions = resolutionStrategy.BuildExpressionsForEnumerableRequest(resolutionContext, newTypeInfo);

            return(expressions == null?newTypeInfo.Type.InitNewArray() :
                       newTypeInfo.Type.InitNewArray(expressions));
        }
Ejemplo n.º 3
0
        public Expression GetExpression(IResolutionStrategy resolutionStrategy, TypeInformation typeInfo,
                                        ResolutionContext resolutionContext)
        {
            var args             = typeInfo.Type.GetGenericArguments();
            var wrappedType      = args.LastElement();
            var funcArgumentInfo = typeInfo.CloneForType(wrappedType);

            var parameters = args.SelectButLast(a => a.AsParameter());
            var expression = resolutionStrategy.BuildExpressionForType(resolutionContext
                                                                       .BeginContextWithFunctionParameters(parameters), funcArgumentInfo);

            return(expression?.AsLambda(typeInfo.Type, parameters));
        }
Ejemplo n.º 4
0
        public IEnumerable <Expression> GetExpressionsForEnumerableRequest(
            IResolutionStrategy resolutionStrategy,
            TypeInformation typeInfo,
            ResolutionContext resolutionContext)
        {
            var lazyArgumentInfo = typeInfo.CloneForType(typeInfo.Type.GetGenericArguments()[0]);

            var ctorParamType   = Constants.FuncType.MakeGenericType(lazyArgumentInfo.Type);
            var lazyConstructor = typeInfo.Type.GetConstructor(ctorParamType);

            return(resolutionStrategy.BuildExpressionsForEnumerableRequest(resolutionContext, lazyArgumentInfo)
                   ?.Select(e => lazyConstructor.MakeNew(e.AsLambda())));
        }
Ejemplo n.º 5
0
        public Expression GetExpression(
            IResolutionStrategy resolutionStrategy,
            TypeInformation typeInfo,
            ResolutionContext resolutionContext)
        {
            var lazyArgumentInfo = typeInfo.CloneForType(typeInfo.Type.GetGenericArguments()[0]);

            var ctorParamType   = Constants.FuncType.MakeGenericType(lazyArgumentInfo.Type);
            var lazyConstructor = typeInfo.Type.GetConstructor(ctorParamType);
            var expression      = this.GetLazyFuncExpression(lazyArgumentInfo, resolutionContext, resolutionStrategy);

            return(expression == null ? null : lazyConstructor.MakeNew(expression.AsLambda()));
        }
Ejemplo n.º 6
0
        public IEnumerable <Expression> GetExpressionsForEnumerableRequest(IResolutionStrategy resolutionStrategy, TypeInformation typeInfo,
                                                                           ResolutionContext resolutionContext)
        {
            var type             = typeInfo.Type;
            var args             = type.GetGenericArguments();
            var wrappedType      = args.LastElement();
            var funcArgumentInfo = typeInfo.CloneForType(wrappedType);

            var parameters = args.SelectButLast(a => a.AsParameter());

            return(resolutionStrategy.BuildExpressionsForEnumerableRequest(resolutionContext
                                                                           .BeginContextWithFunctionParameters(parameters), funcArgumentInfo)?
                   .Select(e => e.AsLambda(type, parameters)));
        }
Ejemplo n.º 7
0
 public IEnumerable <ServiceRegistration> GetDecoratorsOrDefault(Type implementationTypeToDecorate, TypeInformation typeInformation, ResolutionContext resolutionContext) =>
 this.GetRegistrationsForType(typeInformation.Type)?.FilterInclusiveOrDefault(typeInformation.CloneForType(implementationTypeToDecorate), resolutionContext, this.filters);