Exemplo n.º 1
0
        private object EnumerableAssign(object DesitnationObject, PropertyInfo destProp, object data, Type sourceType, PropertyInfo sourceProp, object SourceValues)
        {
            if (((IEnumerable)SourceValues).Cast <object>().Count() > 0)
            {
                if (!MappingPath.Keys.Contains(sourceType))
                {
                    MappingPath.Add(sourceType, new List <string>());
                }
                if (!MappingPath[sourceType].Contains(sourceProp.PropertyType.GetGenericArguments()[0].Name) &&
                    !MappingPath.Keys.Contains(sourceProp.PropertyType.GetGenericArguments()[0]))
                {
                    MappingPath[sourceType].Add(sourceProp.PropertyType.GetGenericArguments()[0].Name);
                    data = InstanceCreator.CreateEnumrableInstance(destProp);

                    foreach (var item in (IEnumerable)SourceValues)
                    {
                        data.GetType().GetMethod("Add").Invoke(data,
                                                               new[] { GetProperties(item,
                                                                                     Activator.CreateInstance(destProp.PropertyType.GetGenericArguments()[0])) });
                        MappingPath.Remove(sourceProp.PropertyType.GetGenericArguments()[0]);
                    }
                    destProp.SetValue(DesitnationObject, data);
                }
            }

            return(data);
        }
Exemplo n.º 2
0
        private object ObjectAssing(object DesitnationObject, PropertyInfo destProp, object data,
                                    Type sourceType, PropertyInfo sourceProp, object SourceValues)
        {
            if (SourceValues != null)
            {
                if (!MappingPath.Keys.Contains(sourceType))
                {
                    MappingPath.Add(sourceType, new List <string>());
                }

                if (!MappingPath[sourceType].Contains(sourceProp.Name) && !MappingPath.Keys.Contains(sourceProp.PropertyType))
                {
                    MappingPath[sourceType].Add(sourceProp.Name);
                    data = InstanceCreator.CreateObjectInstance(destProp);
                    GetProperties(SourceValues, data);
                    MappingPath.Remove(sourceProp.PropertyType);
                    destProp.SetValue(DesitnationObject, data);
                }
            }

            return(data);
        }