public static ConfiguredLambdaInfo For(LambdaExpression lambda) { var funcArguments = lambda.Parameters.ProjectToArray(p => p.Type); var contextTypes = GetContextTypes(funcArguments); var parameterSwapper = ParametersSwapper.For(contextTypes, funcArguments); return(new ConfiguredLambdaInfo(lambda, contextTypes, lambda.ReturnType, parameterSwapper)); }
public static ConfiguredLambdaInfo For(LambdaExpression lambda) { var funcArguments = lambda.Parameters.Select(p => p.Type).ToArray(); var contextTypes = (funcArguments.Length != 1) ? funcArguments : funcArguments[0].GetGenericArguments(); var parameterSwapper = ParametersSwapper.For(contextTypes, funcArguments); return(new ConfiguredLambdaInfo(lambda, lambda.ReturnType, parameterSwapper)); }
private ConfiguredLambdaInfo( LambdaExpression lambda, Type returnType, ParametersSwapper parametersSwapper) { _lambda = lambda; _parametersSwapper = parametersSwapper; ReturnType = returnType; }
private ConfiguredLambdaInfo( LambdaExpression lambda, Type[] contextTypes, Type returnType, ParametersSwapper parametersSwapper) { _lambda = lambda; _contextTypes = contextTypes; _parametersSwapper = parametersSwapper; ReturnType = returnType; _isForTargetDictionary = (contextTypes.Length > 1) && contextTypes[1].IsDictionary(); }
private static ConfiguredLambdaInfo For <T>( T func, Type[] contextTypes, Func <Type[], Type[]> funcArgumentsFactory, Func <Type[], Type> returnTypeFactory, params Type[] allowedTypes) { var funcType = typeof(T); if (!funcType.IsGenericType()) { return(null); } var funcTypeDefinition = funcType.GetGenericTypeDefinition(); if (!allowedTypes.Contains(funcTypeDefinition)) { return(null); } var funcTypes = funcType.GetGenericTypeArguments(); var funcArguments = funcArgumentsFactory.Invoke(funcTypes); var parameterSwapper = ParametersSwapper.For(contextTypes, funcArguments); if (parameterSwapper == null) { return(null); } var parameters = funcArguments.ProjectToArray(Parameters.Create); var valueFactory = func.ToConstantExpression(); var valueFactoryInvocation = Expression.Invoke(valueFactory, parameters.Cast <Expression>()); var valueFactoryLambda = Expression.Lambda(funcType, valueFactoryInvocation, parameters); return(new ConfiguredLambdaInfo( valueFactoryLambda, contextTypes, returnTypeFactory.Invoke(funcTypes), parameterSwapper)); }