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 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); }
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); }