public void TestSetup() { backingEntity1 = new TBackingEntity(); backingEntity2 = new AnotherTableEntity(); model = new TMyModel(backingEntity1); cache = new PropertyMapCache<TBackingEntity>(); }
private object MapDataRow(IDataReader dr, Type type, RowMap rowMap, string mapName, object defaultValue = null) { object obj; if (defaultValue != null) { obj = defaultValue; } else { obj = Activator.CreateInstance(type, null); } bool setReturnValue = false; object rv = null; DataTable schemaTable = dr.GetSchemaTable(); foreach (KeyValuePair <string, ColumnMap> keyValuePair in rowMap.ColumnMapsByPropertyName) { switch (keyValuePair.Value.InnerType) { case InnerMapType.None: { string columnName = keyValuePair.Value.ColumnName; if (HasColumn(columnName, dr, schemaTable)) { PropertyInfo propertyInfo = PropertyMapCache.GetProperty(type, keyValuePair.Value.PropertyName); if (propertyInfo != null) { propertyInfo.SetValue(obj, RowMapperChangeType(dr[columnName], propertyInfo.PropertyType), null); setReturnValue = true; } else { //TODO:Logger throw new Exception("PropertyName Not Found PropertyName=" + keyValuePair.Value.PropertyName + " MapName=" + mapName); } } } break; case InnerMapType.Internal: case InnerMapType.External: { PropertyInfo propertyInfo = PropertyMapCache.GetProperty(type, keyValuePair.Value.PropertyName); if (propertyInfo != null) { if (keyValuePair.Value.InnerType == InnerMapType.Internal) { object value = propertyInfo.GetValue(obj, null); object data = MapDataRow(dr, propertyInfo.PropertyType, keyValuePair.Value.InternalRowMap, "Internal Map For " + mapName + " " + keyValuePair.Value.PropertyName, value); if (value == null) { propertyInfo.SetValue(obj, data, null); } setReturnValue = true; } else if (keyValuePair.Value.InnerType == InnerMapType.External) { object data = GetData(keyValuePair.Value.InnerRowMapName, dr, propertyInfo.PropertyType); propertyInfo.SetValue(obj, data, null); setReturnValue = true; } } else { //TODO:Logger throw new Exception("PropertyName Not Found PropertyName=" + keyValuePair.Value.PropertyName + " MapName=" + mapName); } } break; default: throw new ArgumentOutOfRangeException(); } } if (setReturnValue) { rv = obj; } return(rv); }