/// <summary> /// Initialise a new ObjectDataReader. /// </summary> /// <param name="collection">The collection of things to make a data reader over.</param> /// <param name="nullConversion">How to treat System.Nullable types.</param> public ObjectDataReader(IEnumerable <T> collection, NullConversion nullConversion) { collection.ThrowIfNull("collection"); this.NullConversion = nullConversion; this.Enumerator = collection.GetEnumerator(); // Done without a lock, so we risk running twice. // n.b. This is a scalar property, so the intention is that it is only // discovered once per instantiation of the app domain. if (scalarAttributes == null) { scalarAttributes = DiscoverScalarAttributes(typeof(T)); } Attributes = scalarAttributes; }
/// <summary> /// Wraps the IEnumerable in a DbDataReader, having one column for each "scalar" property of the type T. /// The collection will be enumerated as the client calls IDataReader.Read(). /// </summary> /// <typeparam name="T">The element type of the collectin.</typeparam> /// <param name="collection">A collection to wrap in a DataReader</param> /// <param name="exposeNullableColumns"></param> /// <returns>An IDataReader wrapping the collection.</returns> public static IDataReader AsDataReader <T>(this IEnumerable <T> collection, NullConversion nullConversion) { collection.ThrowIfNull("collection"); return(new ObjectDataReader <T>(collection, nullConversion)); }