Пример #1
0
 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);
 }
Пример #2
0
        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));
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
 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;
 }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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));
        }
Пример #9
0
        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;
        }