Esempio n. 1
0
        public FlattenMemberInfo(PropertyInfo destMember, PropertyInfo[] sourcePathMembers, PropertyInfo lastMemberToAdd,
                                 FlattenLinqMethod linqMethodSuffix = null)
        {
            _destMember       = destMember;
            _linqMethodSuffix = linqMethodSuffix;

            var list = sourcePathMembers.ToList();

            list.Add(lastMemberToAdd);
            _sourcePathMembers = list;
        }
Esempio n. 2
0
        private void ScanSourceClassRecursively(IEnumerable <PropertyInfo> sourceProps, PropertyInfo destProp,
                                                string prefix, PropertyInfo[] sourcePropPath)
        {
            foreach (var matchedStartSrcProp in sourceProps.Where(x => destProp.Name.StartsWith(prefix + x.Name, _stringComparison)))
            {
                var matchStart = prefix + matchedStartSrcProp.Name;
                if (string.Equals(destProp.Name, matchStart, _stringComparison))
                {
                    //direct match of name

                    var underlyingType = Nullable.GetUnderlyingType(destProp.PropertyType);
                    if (destProp.PropertyType == matchedStartSrcProp.PropertyType ||
                        underlyingType == matchedStartSrcProp.PropertyType ||
                        Mapper.MapExists(matchedStartSrcProp.PropertyType, destProp.PropertyType))
                    {
                        //matched a) same type, or b) dest is a nullable version of source
                        _foundFlattens.Add(new FlattenMemberInfo(destProp, sourcePropPath, matchedStartSrcProp));
                        _filteredDestProps.Remove(destProp);        //matched, so take it out
                    }

                    return;
                }

                if (matchedStartSrcProp.PropertyType == typeof(string))
                {
                    //string can only be directly matched
                    continue;
                }

                if (matchedStartSrcProp.PropertyType.GetInfo().IsClass)
                {
                    var classProps = GetPropertiesRightAccess(matchedStartSrcProp.PropertyType);
                    var clonedList = sourcePropPath.ToList();
                    clonedList.Add(matchedStartSrcProp);
                    ScanSourceClassRecursively(classProps, destProp, matchStart, clonedList.ToArray());
                }
                else if (matchedStartSrcProp.PropertyType.GetInfo().GetInterfaces().Any(i => i.Name == "IEnumerable"))
                {
                    //its an enumerable class so see if the end relates to a LINQ method
                    var endOfName       = destProp.Name.Substring(matchStart.Length);
                    var enumeableMethod = FlattenLinqMethod.EnumerableEndMatchsWithLinqMethod(endOfName, _stringComparison);
                    if (enumeableMethod != null)
                    {
                        _foundFlattens.Add(new FlattenMemberInfo(destProp, sourcePropPath, matchedStartSrcProp, enumeableMethod));
                        _filteredDestProps.Remove(destProp);        //matched, so take it out
                    }
                }
            }
        }