private static bool ProcessCustomResolvers( Expression source, Expression destination, TypeAdapterSettings config, IMemberModel destinationMember, List <MemberConverter> properties) { bool isAdded = false; var resolvers = config.Resolvers; if (resolvers != null && resolvers.Count > 0) { MemberConverter memberConverter = null; LambdaExpression lastCondition = null; for (int j = 0; j < resolvers.Count; j++) { var resolver = resolvers[j]; if (destinationMember.Name.Equals(resolver.MemberName)) { if (memberConverter == null) { memberConverter = new MemberConverter { ConvertType = 5, Setter = destinationMember.GetExpression(destination), SetterInfo = destinationMember.Info, }; isAdded = true; } Expression invoke = resolver.Invoker.Apply(source); memberConverter.Getter = lastCondition != null ? Expression.Condition(lastCondition.Apply(source), memberConverter.Getter, invoke) : invoke; lastCondition = resolver.Condition; if (resolver.Condition == null) { break; } } } if (memberConverter != null) { if (lastCondition != null) { memberConverter.Getter = Expression.Condition(lastCondition.Apply(source), memberConverter.Getter, Expression.Constant(memberConverter.Getter.Type.GetDefault(), memberConverter.Getter.Type)); } properties.Add(memberConverter); } } return(isAdded); }
private static bool FlattenClass( Expression source, Expression destination, IMemberModel destinationMember, List <MemberConverter> properties, bool isProjection) { var getter = ReflectionUtils.GetDeepFlattening(source, destinationMember.Name, isProjection); if (getter != null) { var propertyModel = new MemberConverter { ConvertType = 3, Getter = getter, Setter = destinationMember.GetExpression(destination), SetterInfo = destinationMember.Info, }; properties.Add(propertyModel); return(true); } return(false); }
private static bool FlattenMethod( Expression source, Expression destination, IMemberModel destinationMember, List <MemberConverter> properties) { var getMethod = source.Type.GetMethod(string.Concat("Get", destinationMember.Name)); if (getMethod != null) { var propertyModel = new MemberConverter { ConvertType = 2, Getter = Expression.Call(source, getMethod), Setter = destinationMember.GetExpression(destination), SetterInfo = destinationMember.Info, }; properties.Add(propertyModel); return(true); } return(false); }