Exemple #1
0
        private static IDictionary ToDictionaryInternal(IDataReader reader, string keyFileName, IDictionary dictionary, Type targetType)
        {
            IMapDataSource dataSource = GetDataSource(reader);

            TypeDescriptor targetDescriptor = TypeDescriptorFactory.CreateTypeDescriptor(targetType) as TypeDescriptor;

            ArrayList dataDescList = GetTypeMappingList(targetDescriptor, dataSource);

            if (dictionary is ISupportInitialize)
            {
                ((ISupportInitialize)dictionary).BeginInit();
            }

            while (reader.Read())
            {
                object targetObject = Activator.CreateInstance(targetType);
                ToObjectInternal(targetObject, dataSource, dataDescList, null);
                if (targetObject != null)
                {
                    dictionary.Add(dataSource.GetFieldValue(keyFileName), targetObject);
                }
            }
            if (dictionary is ISupportInitialize)
            {
                ((ISupportInitialize)dictionary).EndInit();
            }

            return(dictionary);
        }
        protected override void MapInternal(Reflection.InitContext initContext, IMapDataSource source, object sourceObject, IMapDataDestination dest, object destObject, params object[] parameters)
        {
            FullObjectMapper mapper = (FullObjectMapper)initContext.ObjectMapper;
            IDataReader dataReader = (IDataReader)sourceObject;

            //int[] index = GetIndex(source, dest);
            //IValueMapper[] mappers = GetValueMappers(source, dest, index);

            //foreach (var valueMapper in mappers)
            //{
                
            //}

            InitSchema(dataReader);

            if (mapper.ColParent)
            {
                FillObject(mapper, dataReader, destObject);
                while (dataReader.Read())
                {
                    destObject = FillObject(destObject, mapper, dataReader);
                }
            }
            else
                 FillObject(mapper, dataReader, destObject);
        }
Exemple #3
0
        private static IList ToListInternal(IDataReader reader, IList list, Type targetType)
        {
            IMapDataSource dataSource = GetDataSource(reader);

            TypeDescriptor targetDescriptor = TypeDescriptorFactory.CreateTypeDescriptor(targetType) as TypeDescriptor;

            ArrayList dataDescList = GetTypeMappingList(targetDescriptor, dataSource);

            if (list is ISupportInitialize)
            {
                ((ISupportInitialize)list).BeginInit();
            }

            while (reader.Read())
            {
                object targetObject = Activator.CreateInstance(targetType);
                ToObjectInternal(targetObject, dataSource, dataDescList, null);
                if (targetObject != null)
                {
                    list.Add(targetObject);
                }
            }
            if (list is ISupportInitialize)
            {
                ((ISupportInitialize)list).EndInit();
            }



            return(list);
        }
Exemple #4
0
        private static List <T> ToListInternal <T>(IDataReader reader, List <T> list) where T : new()
        {
            Type targetType = typeof(T);

            IMapDataSource dataSource = GetDataSource(reader);

            TypeDescriptor targetDescriptor = TypeDescriptorFactory.CreateTypeDescriptor(targetType) as TypeDescriptor;

            ArrayList dataDescList = GetTypeMappingList(targetDescriptor, dataSource);

            if (list is ISupportInitialize)
            {
                ((ISupportInitialize)list).BeginInit();
            }

            while (reader.Read())
            {
                T targetObject = new T(); //(T)Activator.CreateInstance(targetType);
                ToObjectInternal(targetObject, dataSource, dataDescList, null);
                if (targetObject != null)
                {
                    list.Add(targetObject);
                }
            }
            if (list is ISupportInitialize)
            {
                ((ISupportInitialize)list).EndInit();
            }



            return(list);
        }
Exemple #5
0
        private static object ToObjectInternal(object targetObject, IMapDataSource dataSource, object objEntity, bool isTargetCollection)
        {
            if (targetObject != null && dataSource != null && targetObject is IMapDataSource)
            {
                IMapDataReceiver targetDataSource = (IMapDataReceiver)targetObject;

                Type sourceType = objEntity.GetType();

                TypeDescriptor sourceDescriptor = TypeDescriptorFactory.CreateTypeDescriptor(sourceType) as TypeDescriptor;

                ArrayList propDescList = sourceDescriptor.PropInfoList;

                int iCnt = 0;

                foreach (PropertyDescriptor propDesc in propDescList)
                {
                    object sourceData = dataSource.GetFieldValue(iCnt, propDesc, objEntity);
                    if (sourceData != null)
                    {
                        targetDataSource.SetFieldValue(iCnt++, propDesc.MappedDBName, null, sourceData);
                    }
                }
            }
            return(targetObject);
        }
Exemple #6
0
        private static IList ToListInternal(DataTable table, IList list, Type targetType)
        {
            IMapDataSource dataSource = GetDataSource(table);

            TypeDescriptor targetDescriptor = TypeDescriptorFactory.CreateTypeDescriptor(targetType) as TypeDescriptor;

            ArrayList dataDescList = GetTypeMappingList(targetDescriptor, dataSource);

            if (list is ISupportInitialize)
            {
                ((ISupportInitialize)list).BeginInit();
            }


            foreach (DataRow row in table.Rows)
            {
                ((DataRowReader)dataSource).DataRow = row;

                object targetObject = Activator.CreateInstance(targetType);

                ToObjectInternal(targetObject, dataSource, dataDescList, null);

                if (targetObject != null)
                {
                    list.Add(targetObject);
                }
            }
            if (list is ISupportInitialize)
            {
                ((ISupportInitialize)list).EndInit();
            }

            return(list);
        }
Exemple #7
0
 public static void MapSourceToDestination(
     IMapDataSource source, object sourceObject,
     IMapDataDestination dest, object destObject,
     params object[]     parameters)
 {
     _defaultSchema.MapSourceToDestination(source, sourceObject, dest, destObject, parameters);
 }
Exemple #8
0
		public object GetValue(IMapDataSource source, object obj, int index)
		{
			if (source == null)
				throw new ArgumentNullException("source");

			var value = Fields[index].ByName?
				source.GetValue(obj, Fields[index].Name):
				source.GetValue(obj, Fields[index].Index);

			if (value == null)
			{
				var objectMapper = source as ObjectMapper;

				if (objectMapper != null)
				{
					var mm = Fields[index].ByName?
						objectMapper[Fields[index].Name]: objectMapper[Fields[index].Index];

					if (mm == null)
						throw new MappingException(string.Format(Resources.MapIndex_BadField,
							objectMapper.TypeAccessor.OriginalType.Name, Fields[index]));
				}
			}

			return value;
		}
Exemple #9
0
        public object GetValue(IMapDataSource source, object obj, int index)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            var value = Fields[index].ByName?
                        source.GetValue(obj, Fields[index].Name):
                        source.GetValue(obj, Fields[index].Index);

            if (value == null)
            {
                var objectMapper = source as ObjectMapper;

                if (objectMapper != null)
                {
                    var mm = Fields[index].ByName?
                             objectMapper[Fields[index].Name]: objectMapper[Fields[index].Index];

                    if (mm == null)
                    {
                        throw new MappingException(string.Format(Resources.MapIndex_BadField,
                                                                 objectMapper.TypeAccessor.OriginalType.Name, Fields[index]));
                    }
                }
            }

            return(value);
        }
Exemple #10
0
        protected override void MapInternal(Reflection.InitContext initContext, IMapDataSource source, object sourceObject, IMapDataDestination dest, object destObject, params object[] parameters)
        {
            FullObjectMapper mapper     = (FullObjectMapper)initContext.ObjectMapper;
            IDataReader      dataReader = (IDataReader)sourceObject;

            //int[] index = GetIndex(source, dest);
            //IValueMapper[] mappers = GetValueMappers(source, dest, index);

            //foreach (var valueMapper in mappers)
            //{

            //}

            InitSchema(dataReader);

            if (mapper.ColParent)
            {
                FillObject(mapper, dataReader, destObject);
                while (dataReader.Read())
                {
                    destObject = FillObject(destObject, mapper, dataReader);
                }
            }
            else
            {
                FillObject(mapper, dataReader, destObject);
            }
        }
Exemple #11
0
        public object GetValueOrIndex(IMapDataSource source, object obj)
        {
            if (Fields.Length == 1)
            {
                return(GetValue(source, obj, 0));
            }

            return(GetIndexValue(source, obj));
        }
Exemple #12
0
            public void Map(
                IMapDataSource source, object sourceObject, int sourceIndex,
                IMapDataDestination dest, object destObject, int destIndex)
            {
                dest.SetValue(destObject, destIndex, source.GetValue(sourceObject, sourceIndex));

                //object o = source.GetValue(sourceObject, sourceIndex);

                //if (o == null) dest.SetNull (destObject, destIndex);
                //else           dest.SetValue(destObject, destIndex, o);
            }
Exemple #13
0
        public CompoundValue GetIndexValue(IMapDataSource source, object obj)
        {
            object[] values = new string[Fields.Length];

            for (int i = 0; i < values.Length; i++)
            {
                values[i] = GetValue(source, obj, i);
            }

            return(new CompoundValue(values));
        }
Exemple #14
0
 private static object ToObjectInternal(object targetObject, IMapDataSource dataSource, ArrayList dataDescList, object objEntity)
 {
     if (targetObject != null && dataSource != null && dataDescList != null)
     {
         foreach (DataDescriptor dataDesc in dataDescList)
         {
             object sourceData = dataSource.GetFieldValue(dataDesc.ColumnPosition, dataDesc.PropertyDescription, objEntity);
             if (sourceData != null || dataDesc.PropertyDescription.IsEnum)
             {
                 dataDesc.PropertyDescription.SetValue(targetObject, sourceData);
             }
         }
     }
     return(targetObject);
 }
Exemple #15
0
            public void Map(
                IMapDataSource source, object sourceObject, int sourceIndex,
                IMapDataDestination dest, object destObject, int destIndex)
            {
                if (source.IsNull(sourceObject, sourceIndex))
                {
                    dest.SetNull(destObject, destIndex);
                }
                else
                {
                    var setter = MapSetData <T> .I;
                    var getter = MapGetData <T> .I;

                    setter.To(dest, destObject, destIndex,
                              getter.From(source, sourceObject, sourceIndex));
                }
            }
Exemple #16
0
        public static object ToObject(object source, Type targetType)
        {
            IMapDataSource dataSource = GetDataSource(source);

            object targetObject = Activator.CreateInstance(targetType);

            if (targetObject != null && dataSource != null)
            {
                TypeDescriptor targetDescriptor = TypeDescriptorFactory.CreateTypeDescriptor(targetType) as TypeDescriptor;

                ArrayList dataDescList = GetTypeMappingList(targetDescriptor, dataSource);

                //The Source has to be passed as the last parameter in ToObjectInternal call!
                targetObject = ToObjectInternal(targetObject, dataSource, dataDescList, source);
            }

            return(targetObject);
        }
Exemple #17
0
        public static IMapDataSource CreateTypeDescriptor(Type targetType)
        {
            IMapDataSource instance = null;

            lock (_typeDescriptorList)
            {
                instance = _typeDescriptorList[targetType.Name] as IMapDataSource;
                if (instance == null)
                {
                    instance = new TypeDescriptor(targetType);
                    if (instance != null)
                    {
                        _typeDescriptorList.Add(targetType.Name, instance);
                    }
                }
            }

            return(instance);
        }
Exemple #18
0
        public static T ToObject <T>(object source) where T : new()
        {
            Type targetType = typeof(T);

            IMapDataSource dataSource = GetDataSource(source);

            T targetObject = new T(); //Activator.CreateInstance(targetType);

            if (targetObject != null && dataSource != null)
            {
                TypeDescriptor targetDescriptor = TypeDescriptorFactory.CreateTypeDescriptor(targetType) as TypeDescriptor;

                ArrayList dataDescList = GetTypeMappingList(targetDescriptor, dataSource);

                //The Source has to be passed as the last parameter in ToObjectInternal call!
                targetObject = ToObjectInternal(targetObject, dataSource, dataDescList, source);
            }

            return(targetObject);
        }
Exemple #19
0
		public object GetValue(IMapDataSource source, object obj, int index)
		{
			object value = _fields[index].ByName ?
				source.GetValue(obj, _fields[index].Name) : source.GetValue(obj, _fields[index].Index);

			if (value == null)
			{
				ObjectMapper objectMapper = source as ObjectMapper;

				if (objectMapper != null)
				{
					MemberMapper mm = _fields[index].ByName ?
						objectMapper[_fields[index].Name] : objectMapper[_fields[index].Index];

					if (mm == null)
						throw new MappingException(string.Format("Type '{0}' does not contain field '{1}'.",
							objectMapper.TypeAccessor.OriginalType.Name, Fields[index]));
				}
			}

			return value;
		}
Exemple #20
0
        private static ArrayList GetTypeMappingList(TypeDescriptor targetDescriptor, IMapDataSource dataSource)
        {
            ArrayList dataDescList = new ArrayList();

            if (dataSource != null)
            {
                for (int cnt = 0; cnt < dataSource.FieldCount; cnt++)
                {
                    string sourceColName = dataSource.GetFieldName(cnt);

                    PropertyDescriptor[] propDescList = null;

                    if ((dataSource is DataRowReader) || (dataSource is DataReaderSource) ||
                        ((dataSource is IMapDataSource) && ((IMapDataSource)dataSource).IsCollection()))
                    {
                        propDescList = targetDescriptor.GetOrdinalByDBColnName(sourceColName.ToUpper());
                    }
                    else
                    {
                        propDescList = targetDescriptor.GetOrdinalByPropName(sourceColName.ToUpper());
                    }


                    if (propDescList != null && propDescList.Length > 0)
                    {
                        foreach (PropertyDescriptor desc in propDescList)
                        {
                            DataDescriptor dataDesc = new DataDescriptor(sourceColName.ToUpper(), cnt, desc);

                            dataDescList.Add(dataDesc);
                        }
                    }
                }
            }

            return(dataDescList);
        }
Exemple #21
0
        public object GetValue(IMapDataSource source, object obj, int index)
        {
            object value = _fields[index].ByName ?
                           source.GetValue(obj, _fields[index].Name) : source.GetValue(obj, _fields[index].Index);

            if (value == null)
            {
                ObjectMapper objectMapper = source as ObjectMapper;

                if (objectMapper != null)
                {
                    MemberMapper mm = _fields[index].ByName ?
                                      objectMapper[_fields[index].Name] : objectMapper[_fields[index].Index];

                    if (mm == null)
                    {
                        throw new MappingException(string.Format("Type '{0}' does not contain field '{1}'.",
                                                                 objectMapper.TypeAccessor.OriginalType.Name, Fields[index]));
                    }
                }
            }

            return(value);
        }
Exemple #22
0
        public static object ToObject(object source, object targetObject)
        {
            IMapDataSource dataSource = GetDataSource(source);

            if (targetObject != null && dataSource != null)
            {
                if ((targetObject is IMapDataSource) && (((IMapDataSource)targetObject).IsCollection() == true))
                {
                    targetObject = ToObjectInternal(targetObject, dataSource, source, true);
                }
                else
                {
                    Type targetType = targetObject.GetType();

                    TypeDescriptor targetDescriptor = TypeDescriptorFactory.CreateTypeDescriptor(targetType) as TypeDescriptor;

                    ArrayList dataDescList = GetTypeMappingList(targetDescriptor, dataSource);

                    targetObject = ToObjectInternal(targetObject, dataSource, dataDescList, source);
                }
            }

            return(targetObject);
        }
Exemple #23
0
 // SqlTypes.
 //
 sealed class dbS : MB <SqlString>   { public override SqlString   From(IMapDataSource s, object o, int i)
                                       {
                                           return(s.GetSqlString(o, i));
                                       }
Exemple #24
0
 public override void Map(IMapDataSource source, object sourceObject, int sourceIndex, IMapDataDestination destination, object destinationObject, int destinationIndex)
 {
     if(source.IsNull(sourceObject, sourceIndex))
     {
         destination.SetNullableDateTime(destinationObject, destinationIndex, null);
     }
     else
     {
         destination.SetNullableDateTime(destinationObject, destinationIndex, Convert.ToDateTime(source.GetBoolean(sourceObject, sourceIndex)));
     }
 }
Exemple #25
0
 sealed class dbI16 : MB <SqlInt16>    { public override SqlInt16    From(IMapDataSource s, object o, int i)
                                         {
                                             return(s.GetSqlInt16(o, i));
                                         }
Exemple #26
0
 public override void Map(IMapDataSource source, object sourceObject, int sourceIndex, IMapDataDestination destination, object destinationObject, int destinationIndex)
 {
     if(source.IsNull(sourceObject, sourceIndex))
     {
         destination.SetFloat(destinationObject, destinationIndex, 0);
     }
     else
     {
         destination.SetFloat(destinationObject, destinationIndex, Convert.ToSingle(source.GetString(sourceObject, sourceIndex)));
     }
 }
Exemple #27
0
 sealed class dbDT : MB <SqlDateTime> { public override SqlDateTime From(IMapDataSource s, object o, int i)
                                        {
                                            return(s.GetSqlDateTime(o, i));
                                        }
		public SimpleSourceListMapper(IMapDataSource mapper)
		{
			_mapper = mapper;
		}
Exemple #29
0
 public override void Map(IMapDataSource source, object sourceObject, int sourceIndex, IMapDataDestination destination, object destinationObject, int destinationIndex)
 {
     if(source.IsNull(sourceObject, sourceIndex))
     {
         destination.SetBoolean(destinationObject, destinationIndex, false);
     }
     else
     {
         destination.SetBoolean(destinationObject, destinationIndex, Convert.ToBoolean(source.GetFloat(sourceObject, sourceIndex)));
     }
 }
Exemple #30
0
 sealed class dbG : MB <SqlGuid>     { public override SqlGuid     From(IMapDataSource s, object o, int i)
                                       {
                                           return(s.GetSqlGuid(o, i));
                                       }
Exemple #31
0
 public override void Map(IMapDataSource source, object sourceObject, int sourceIndex, IMapDataDestination destination, object destinationObject, int destinationIndex)
 {
     if(source.IsNull(sourceObject, sourceIndex))
     {
         destination.SetNullableInt64(destinationObject, destinationIndex, null);
     }
     else
     {
         destination.SetNullableInt64(destinationObject, destinationIndex, Convert.ToInt64(source.GetFloat(sourceObject, sourceIndex)));
     }
 }
 public SimpleSourceListMapper(IMapDataSource mapper)
 {
     _mapper = mapper;
 }
Exemple #33
0
 sealed class dbD : MB <SqlDecimal>  { public override SqlDecimal  From(IMapDataSource s, object o, int i)
                                       {
                                           return(s.GetSqlDecimal(o, i));
                                       }
Exemple #34
0
 public override void Map(IMapDataSource source, object sourceObject, int sourceIndex, IMapDataDestination destination, object destinationObject, int destinationIndex)
 {
     if(source.IsNull(sourceObject, sourceIndex))
     {
         destination.SetDecimal(destinationObject, destinationIndex, 0);
     }
     else
     {
         destination.SetDecimal(destinationObject, destinationIndex, Convert.ToDecimal(source.GetByte(sourceObject, sourceIndex)));
     }
 }
Exemple #35
0
 public abstract void Map(IMapDataSource source, object sourceObject, int sourceIndex, IMapDataDestination destination, object destinationObject, int destinationIndex);
Exemple #36
0
 public override void Map(IMapDataSource source, object sourceObject, int sourceIndex, IMapDataDestination destination, object destinationObject, int destinationIndex)
 {
     if(source.IsNull(sourceObject, sourceIndex))
     {
         destination.SetChar(destinationObject, destinationIndex, '\0');
     }
     else
     {
         destination.SetChar(destinationObject, destinationIndex, Convert.ToChar(source.GetNullableInt32(sourceObject, sourceIndex)));
     }
 }
Exemple #37
0
		public CompoundValue GetIndexValue(IMapDataSource source, object obj)
		{
			object[] values = new string[Fields.Length];

			for (int i = 0; i < values.Length; i++)
				values[i] = GetValue(source, obj, i);

			return new CompoundValue(values);
		}
Exemple #38
0
 sealed class dbM : MB <SqlMoney>    { public override SqlMoney    From(IMapDataSource s, object o, int i)
                                       {
                                           return(s.GetSqlMoney(o, i));
                                       }
Exemple #39
0
 sealed class dbR8 : MB <SqlDouble>   { public override SqlDouble   From(IMapDataSource s, object o, int i)
                                        {
                                            return(s.GetSqlDouble(o, i));
                                        }
			public void Map(
				IMapDataSource source, object sourceObject, int sourceIndex,
				IMapDataDestination dest, object destObject, int destIndex)
			{
				dest.SetValue(destObject, destIndex, source.GetValue(sourceObject, sourceIndex));

				//object o = source.GetValue(sourceObject, sourceIndex);

				//if (o == null) dest.SetNull (destObject, destIndex);
				//else           dest.SetValue(destObject, destIndex, o);
			}
Exemple #41
0
 sealed class dbI64 : MB <SqlInt64>    { public override SqlInt64    From(IMapDataSource s, object o, int i)
                                         {
                                             return(s.GetSqlInt64(o, i));
                                         }
Exemple #42
0
		public object GetValueOrIndex(IMapDataSource source, object obj)
		{
			return Fields.Length == 1?
				GetValue(source, obj, 0):
				GetIndexValue(source, obj);
		}
Exemple #43
0
 sealed class dbI32 : MB <SqlInt32>    { public override SqlInt32    From(IMapDataSource s, object o, int i)
                                         {
                                             return(s.GetSqlInt32(o, i));
                                         }
Exemple #44
0
		public object GetValueOrIndex(IMapDataSource source, object obj)
		{
			if (Fields.Length == 1)
				return GetValue(source, obj, 0);

			return GetIndexValue(source, obj);
		}
Exemple #45
0
 public override void Map(IMapDataSource source, object sourceObject, int sourceIndex, IMapDataDestination destination, object destinationObject, int destinationIndex)
 {
     if(source.IsNull(sourceObject, sourceIndex))
     {
         destination.SetDateTime(destinationObject, destinationIndex, DateTime.MinValue);
     }
     else
     {
         destination.SetDateTime(destinationObject, destinationIndex, Convert.ToDateTime(source.GetString(sourceObject, sourceIndex)));
     }
 }
Exemple #46
0
 public override void Map(IMapDataSource source, object sourceObject, int sourceIndex, IMapDataDestination destination, object destinationObject, int destinationIndex)
 {
     if(source.IsNull(sourceObject, sourceIndex))
     {
         destination.SetString(destinationObject, destinationIndex, null);
     }
     else
     {
         destination.SetString(destinationObject, destinationIndex, source.GetString(sourceObject, sourceIndex));
     }
 }
Exemple #47
0
 sealed class dbB : MB <SqlBoolean>  { public override SqlBoolean  From(IMapDataSource s, object o, int i)
                                       {
                                           return(s.GetSqlBoolean(o, i));
                                       }