private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo, IProfileConfiguration options) { var ctorParameters = destCtor.GetParameters(); if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled) { return(false); } var ctorMap = new ConstructorMap(destCtor, typeMap); foreach (var parameter in ctorParameters) { var resolvers = new LinkedList <IMemberGetter>(); var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, destCtor.DeclaringType, parameter.GetType(), parameter.Name, resolvers); if (!canResolve && parameter.HasDefaultValue) { canResolve = true; } ctorMap.AddParameter(parameter, resolvers.ToArray(), canResolve); } typeMap.ConstructorMap = ctorMap; return(true); }
public bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo, List <ICtorParameterConfiguration> ctorParamConfigurations) { var ctorParameters = destCtor.GetParameters(); if (ctorParameters.Length == 0 || !ConstructorMappingEnabled) { return(false); } var ctorMap = new ConstructorMap(destCtor, typeMap); foreach (var parameter in ctorParameters) { var resolvers = new LinkedList <MemberInfo>(); var canResolve = MapDestinationPropertyToSource(sourceTypeInfo, destCtor.DeclaringType, parameter.GetType(), parameter.Name, resolvers); if ((!canResolve && parameter.IsOptional) || ctorParamConfigurations.Any(c => c.CtorParamName == parameter.Name)) { canResolve = true; } ctorMap.AddParameter(parameter, resolvers.ToArray(), canResolve); } typeMap.ConstructorMap = ctorMap; return(ctorMap.CanResolve); }
private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo, ProfileMap options) { var ctorParameters = destCtor.GetParameters(); if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled) return false; var ctorMap = new ConstructorMap(destCtor, typeMap); foreach (var parameter in ctorParameters) { var resolvers = new LinkedList<MemberInfo>(); var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, destCtor.DeclaringType, parameter.GetType(), parameter.Name, resolvers); if(!canResolve && parameter.HasDefaultValue) { canResolve = true; } ctorMap.AddParameter(parameter, resolvers.ToArray(), canResolve); } typeMap.ConstructorMap = ctorMap; return true; }
internal LambdaExpression DestinationConstructorExpression(Expression instanceParameter) { var ctorExpr = ConstructExpression; if (ctorExpr != null) { return(ctorExpr); } Expression newExpression; if (ConstructorMap != null && ConstructorMap.CtorParams.All(p => p.CanResolve)) { newExpression = ConstructorMap.NewExpression(instanceParameter); } else { newExpression = Expression.New(DestinationTypeOverride ?? DestinationType); } return(Expression.Lambda(newExpression)); }
public void AddConstructorMap(ConstructorInfo constructorInfo, IEnumerable <ConstructorParameterMap> parameters) { var ctorMap = new ConstructorMap(constructorInfo, parameters); _constructorMap = ctorMap; }
public void AddConstructorMap(ConstructorInfo constructorInfo, IEnumerable<ConstructorParameterMap> parameters) { var ctorMap = new ConstructorMap(constructorInfo, parameters); _constructorMap = ctorMap; }