/// <summary> /// Dumps all columns into an array for simple use cases. /// </summary> /// <param name="reader">The reader.</param> /// <param name="checker">The column checker.</param> /// <returns>dynamic.</returns> public IEnumerable Deserialize(DbDataReader reader, ColumnChecker checker) { var fieldCount = reader.FieldCount; checker = checker ?? new ColumnChecker(fieldCount); var needsFieldNames = fieldCount > checker.Count; while (reader.Read()) { object[] values; if (needsFieldNames) { var obj = new List <object>(); for (var i = 0; i < fieldCount; i++) { checker.HasColumn(reader, i); obj.Add(reader.GetValue(i)); } values = obj.ToArray(); } else { values = new object[fieldCount]; reader.GetValues(values); } yield return(new DynamicRow(checker, values)); } }
/// <summary> /// Deserializes into a KeyValuePair from a data reader. /// </summary> /// <param name="reader">The data reader.</param> /// <param name="checker">The column object.</param> /// <returns>IEnumerable<TResult>.</returns> public IEnumerable Deserialize(DbDataReader reader, ColumnChecker checker) { var keyAlias = "Key"; IPropertyMapping keyMapping; var valueAlias = "Value"; IPropertyMapping valueMapping; if (_props.TryGetValue("Key", out keyMapping)) { keyAlias = keyMapping.ActiveAlias; } if (_props.TryGetValue("Value", out valueMapping)) { valueAlias = valueMapping.ActiveAlias; } var resultType = DeserializationType; var genericTypeArguments = resultType.GetTypeInfo().GetGenericArguments(); checker = checker ?? new ColumnChecker(reader.FieldCount); while (reader.Read()) { yield return(Activator.CreateInstance(resultType, Convert.ChangeType(reader.GetValue(checker.HasColumn(reader, keyAlias)), genericTypeArguments[0]), Convert.ChangeType(reader.GetValue(checker.HasColumn(reader, valueAlias)), genericTypeArguments[1]))); } }