private static Expression NewExpr(this Type baseType, Type ifInterfaceType) { var newExpr = baseType.IsInterface() ? New( ifInterfaceType.MakeGenericType(ElementTypeHelper.GetElementTypes(baseType, ElementTypeFlags.BreakKeyValuePair))) : DelegateFactory.GenerateConstructorExpression(baseType); return(newExpr); }
public static Expression MapKeyPairValueExpr(IConfigurationProvider configurationProvider, ProfileMap profileMap, Type sourceType, Type destType, Expression contextParam, out ParameterExpression itemParam) { var sourceElementTypes = ElementTypeHelper.GetElementTypes(sourceType, ElementTypeFlags.BreakKeyValuePair); var destElementTypes = ElementTypeHelper.GetElementTypes(destType, ElementTypeFlags.BreakKeyValuePair); var typePairKey = new TypePair(sourceElementTypes[0], destElementTypes[0]); var typePairValue = new TypePair(sourceElementTypes[1], destElementTypes[1]); var sourceElementType = typeof(KeyValuePair <,>).MakeGenericType(sourceElementTypes); itemParam = Parameter(sourceElementType, "item"); var destElementType = typeof(KeyValuePair <,>).MakeGenericType(destElementTypes); var keyExpr = MapExpression(configurationProvider, profileMap, typePairKey, Property(itemParam, "Key"), contextParam); var valueExpr = MapExpression(configurationProvider, profileMap, typePairValue, Property(itemParam, "Value"), contextParam); var keyPair = New(destElementType.GetDeclaredConstructors().First(), keyExpr, valueExpr); return(keyPair); }