Exemple #1
0
        protected void ProcessAutoProperties()
        {
            var getFields =
                typeof(T).GetFields(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public);
            var setFields =
                typeof(TN).GetFields(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public);

            var getProps =
                typeof(T).GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public);
            var setProps =
                typeof(TN).GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public);

            var sourceMembers = getFields.Cast <MemberInfo>().Union(getProps);
            var destMembers   = setFields.Cast <MemberInfo>().Union(setProps);

            foreach (var prop in sourceMembers)
            {
                if (IgnoreMemberList.Contains(prop.Name) || CustomPropertyCache.ContainsKey(prop.Name))
                {
                    continue;
                }
                var setprop = destMembers.FirstOrDefault(x => string.Equals(x.Name, prop.Name, StringComparison.OrdinalIgnoreCase));

                var propertyInfo = setprop as PropertyInfo;
                if ((propertyInfo == null && setprop == null) || (propertyInfo != null && (!propertyInfo.CanWrite || !propertyInfo.GetSetMethod(true).IsPublic)))
                {
                    IgnoreMemberList.Add(prop.Name);
                    continue;
                }
                AutoMembers[prop] = setprop;
                AutoMapProperty(prop, setprop);
            }
        }
        protected void ProcessAutoProperties()
        {
            var getFields =
                typeof(T).GetInfo()
                .GetFields(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public);
            var setFields =
                typeof(TN).GetInfo()
                .GetFields(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public);

            var getProps =
                typeof(T).GetInfo()
                .GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public);

            var setProps =
                typeof(TN).GetInfo()
                .GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public);

            var sourceMembers = getFields.Cast <MemberInfo>().Union(getProps);
            var destMembers   = setFields.Cast <MemberInfo>().Union(setProps);

            var stringComparison = GetStringCase();

            var comparer = CultureInfo.CurrentCulture.CompareInfo.GetStringComparer(CompareOptions.OrdinalIgnoreCase);

            //var comparer = StringComparer.Create(CultureInfo.CurrentCulture,
            //    stringComparison == StringComparison.OrdinalIgnoreCase);

            foreach (var prop in sourceMembers)
            {
                if (IgnoreMemberList.Contains(prop.Name, comparer) ||
                    CustomPropertyCache.Keys.Contains(prop.Name, comparer))
                {
                    continue;
                }

                var notUniqueDestMembers = destMembers.Where(x => string.Equals(x.Name, prop.Name, stringComparison));
                var notUniqueSrcMembers  = sourceMembers.Where(x => string.Equals(x.Name, prop.Name, stringComparison));

                var getprop = GetTopMostMemberOfHierarchy(notUniqueSrcMembers);
                if (AutoMembers.ContainsKey(getprop))
                {
                    continue;
                }

                var setprop = GetTopMostMemberOfHierarchy(notUniqueDestMembers);

                var propertyInfo = setprop as PropertyInfo;
                if ((propertyInfo == null && setprop == null) ||
                    (propertyInfo != null && (!propertyInfo.CanWrite || !propertyInfo.GetSetMethod(true).IsPublic)))
                {
                    IgnoreMemberList.Add(getprop.Name);
                    continue;
                }
                AutoMembers[getprop] = setprop;
                AutoMapProperty(getprop, setprop);
            }
        }
Exemple #3
0
        public virtual void Ignore <TMember>(Expression <Func <TN, TMember> > left)
        {
            var memberExpression = left.Body as MemberExpression;

            IgnoreMemberList.Add(memberExpression.Member.Name);
        }
 public void Ignore(PropertyInfo left)
 {
     IgnoreMemberList.Add(left.Name);
 }