public void RecursiveMap(object obj)
            {
                //if object is list of something
                if (obj as IEnumerable != null)
                {
                    var items = (IEnumerable)obj;
                    foreach (var item in items)
                    {
                        RecursiveMap(item);
                    }
                }
                //handle non-collections
                else
                {
                    foreach (var propertyInfo in obj.GetType().GetProperties().Where(x => x.CanRead))
                    {
                        _propertyStack.Push(propertyInfo);

                        var propVal         = propertyInfo.GetValue(obj, null);
                        var propertyMapItem = new PropertyMapItem(propertyInfo.Name, propertyInfo.PropertyType, propVal, _currentPath());
                        _map.Add(propertyMapItem);

                        if (!ShouldIgnore(propertyInfo) && propVal != null)
                        {
                            RecursiveMap(propVal);
                        }

                        _propertyStack.Pop();
                    }
                }
            }
Ejemplo n.º 2
0
        protected IIntermediateObject CreateObject(Map map)
        {
            if (!profiles.ContainsKey(map.From) || !profiles.ContainsKey(map.To))
            {
                return(null); // handle better
            }
            var from = profiles[map.From];
            var to   = profiles[map.To];

            var propertyMap = new List <PropertyMapItem>();

            foreach (var item in map.Items)
            {
                propertyMap.Add(PropertyMapItem.Create(item.Name, from, to, item.From, item.To));
            }



            var obj = IntermediateObject.Create(from, to, propertyMap.ToArray());



            //Raise event to get data - populate object
            obj.GenerateProperties(GetData(map).ToArray());


            return(obj);
        }