private static bool ProcessIgnores(TypeAdapterSettings config, IMemberModel destinationMember) { if (config.IgnoreMembers.Contains(destinationMember.Name)) return true; var attributes = destinationMember.GetCustomAttributes(true).Select(attr => attr.GetType()); return config.IgnoreAttributes.Overlaps(attributes); }
private static bool ProcessIgnores(TypeAdapterSettings config, MemberInfo destinationMember) { if (config.IgnoreMembers.Contains(destinationMember.Name)) { return(true); } var attributes = destinationMember.GetCustomAttributes(true).Select(attr => attr.GetType()); return(config.IgnoreAttributes.Overlaps(attributes)); }
private static bool ProcessCustomResolvers( Expression source, Expression destination, TypeAdapterSettings config, MemberInfo destinationMember, List <PropertyModel> properties) { bool isAdded = false; var resolvers = config.Resolvers; if (resolvers != null && resolvers.Count > 0) { PropertyModel propertyModel = null; LambdaExpression lastCondition = null; for (int j = 0; j < resolvers.Count; j++) { var resolver = resolvers[j]; if (destinationMember.Name.Equals(resolver.MemberName)) { if (propertyModel == null) { propertyModel = new PropertyModel { ConvertType = 5, Setter = destinationMember is PropertyInfo ? Expression.Property(destination, (PropertyInfo)destinationMember) : Expression.Field(destination, (FieldInfo)destinationMember), SetterProperty = destinationMember, }; isAdded = true; } Expression invoke = resolver.Invoker.Apply(source); propertyModel.Getter = lastCondition != null ? Expression.Condition(lastCondition.Apply(source), propertyModel.Getter, invoke) : invoke; lastCondition = resolver.Condition; if (resolver.Condition == null) { break; } } } if (propertyModel != null) { if (lastCondition != null) { propertyModel.Getter = Expression.Condition(lastCondition.Apply(source), propertyModel.Getter, Expression.Constant(propertyModel.Getter.Type.GetDefault(), propertyModel.Getter.Type)); } properties.Add(propertyModel); } } return(isAdded); }
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); }
public TypeAdapterRule CreateRule() { var settings = new TypeAdapterSettings(); settings.AfterMappingFactories.Add(this.CreateAfterMapFunc); var rule = new TypeAdapterRule { Priority = this.Priority, Settings = settings, }; DecorateRule(rule); return rule; }
public TypeAdapterRule CreateRule() { var settings = new TypeAdapterSettings(); settings.AfterMappingFactories.Add(this.CreateAfterMapFunc); var rule = new TypeAdapterRule { Priority = this.Priority, Settings = settings, }; DecorateRule(rule); return(rule); }
protected static bool ProcessIgnores( TypeAdapterSettings config, IMemberModel destinationMember, out LambdaExpression condition) { condition = null; if (!destinationMember.ShouldMapMember(config.ShouldMapMember, MemberSide.Destination)) { return(true); } return(config.IgnoreIfs.TryGetValue(destinationMember.Name, out condition) && condition == null); }
private static bool ProcessIgnores( TypeAdapterSettings config, IMemberModel destinationMember, Expression source, out LambdaExpression condition) { if (config.IgnoreMembers.TryGetValue(destinationMember.Name, out condition)) { return(condition == null); } var attributes = destinationMember.GetCustomAttributes(true).Select(attr => attr.GetType()); return(config.IgnoreAttributes.Overlaps(attributes)); }
private static bool ProcessCustomResolvers( Expression source, Expression destination, TypeAdapterSettings config, MemberInfo destinationMember, List<PropertyModel> properties) { bool isAdded = false; var resolvers = config.Resolvers; if (resolvers != null && resolvers.Count > 0) { PropertyModel propertyModel = null; LambdaExpression lastCondition = null; for (int j = 0; j < resolvers.Count; j++) { var resolver = resolvers[j]; if (destinationMember.Name.Equals(resolver.MemberName)) { if (propertyModel == null) { propertyModel = new PropertyModel { ConvertType = 5, Setter = destinationMember is PropertyInfo ? Expression.Property(destination, (PropertyInfo) destinationMember) : Expression.Field(destination, (FieldInfo) destinationMember), SetterProperty = destinationMember, }; isAdded = true; } Expression invoke = resolver.Invoker.Apply(source); propertyModel.Getter = lastCondition != null ? Expression.Condition(lastCondition.Apply(source), propertyModel.Getter, invoke) : invoke; lastCondition = resolver.Condition; if (resolver.Condition == null) break; } } if (propertyModel != null) { if (lastCondition != null) propertyModel.Getter = Expression.Condition(lastCondition.Apply(source), propertyModel.Getter, Expression.Constant(propertyModel.Getter.Type.GetDefault(), propertyModel.Getter.Type)); properties.Add(propertyModel); } } return isAdded; }