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); }
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); }
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); }
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); }
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); }
public static void MapSourceToDestination( IMapDataSource source, object sourceObject, IMapDataDestination dest, object destObject, params object[] parameters) { _defaultSchema.MapSourceToDestination(source, sourceObject, dest, destObject, parameters); }
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; }
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); }
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); } }
public object GetValueOrIndex(IMapDataSource source, object obj) { if (Fields.Length == 1) { return(GetValue(source, obj, 0)); } return(GetIndexValue(source, obj)); }
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); }
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)); }
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); }
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)); } }
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); }
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); }
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); }
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; }
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); }
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); }
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); }
// SqlTypes. // sealed class dbS : MB <SqlString> { public override SqlString From(IMapDataSource s, object o, int i) { return(s.GetSqlString(o, i)); }
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))); } }
sealed class dbI16 : MB <SqlInt16> { public override SqlInt16 From(IMapDataSource s, object o, int i) { return(s.GetSqlInt16(o, i)); }
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))); } }
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; }
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))); } }
sealed class dbG : MB <SqlGuid> { public override SqlGuid From(IMapDataSource s, object o, int i) { return(s.GetSqlGuid(o, i)); }
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))); } }
sealed class dbD : MB <SqlDecimal> { public override SqlDecimal From(IMapDataSource s, object o, int i) { return(s.GetSqlDecimal(o, i)); }
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))); } }
public abstract void Map(IMapDataSource source, object sourceObject, int sourceIndex, IMapDataDestination destination, object destinationObject, int destinationIndex);
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))); } }
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); }
sealed class dbM : MB <SqlMoney> { public override SqlMoney From(IMapDataSource s, object o, int i) { return(s.GetSqlMoney(o, i)); }
sealed class dbR8 : MB <SqlDouble> { public override SqlDouble From(IMapDataSource s, object o, int i) { return(s.GetSqlDouble(o, i)); }
sealed class dbI64 : MB <SqlInt64> { public override SqlInt64 From(IMapDataSource s, object o, int i) { return(s.GetSqlInt64(o, i)); }
public object GetValueOrIndex(IMapDataSource source, object obj) { return Fields.Length == 1? GetValue(source, obj, 0): GetIndexValue(source, obj); }
sealed class dbI32 : MB <SqlInt32> { public override SqlInt32 From(IMapDataSource s, object o, int i) { return(s.GetSqlInt32(o, i)); }
public object GetValueOrIndex(IMapDataSource source, object obj) { if (Fields.Length == 1) return GetValue(source, obj, 0); return GetIndexValue(source, obj); }
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))); } }
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)); } }
sealed class dbB : MB <SqlBoolean> { public override SqlBoolean From(IMapDataSource s, object o, int i) { return(s.GetSqlBoolean(o, i)); }