/// <summary> /// Asynchronous. An extension method for the <see cref="IDataRowProvider"/>. Used to produce a list of objects. /// </summary> /// <typeparam name="T">The type of object represented by the lookup.</typeparam> /// <param name="dataRowProvider">The <see cref="IDataRowProvider"/> used to submit query.</param> /// <param name="dataOrder">The information for the query.</param> /// <param name="converter">A callback used to convert the combination of the <see cref="DataRow"/>, and the <see cref="IAliasedCommandTypeDataOrder"/> into an object of type T.</param> /// <returns>A <see cref='Task'/> with a result of <see cref="Utilities.OperationResult{T}"/> containing result upon success, and Exceptions upon failure.</returns> public static async Task <OperationResult <List <T> > > GetTableAsync <T>(this IDataRowProvider dataRowProvider, IAliasedCommandTypeDataOrder dataOrder, Func <IAliasedCommandTypeDataOrder, DataRow, T> converter) { var operation = await dataRowProvider.SubmitQueryWithDataOrderAsync(dataOrder); return(operation.HadErrors ? new OperationResult <List <T> >(operation.Exceptions) : new OperationResult <List <T> >(await Task.Run(() => operation.Result.Select(row => converter(dataOrder, row)).ToList()))); }
/// <summary> /// Asynchronous. An extension method for the <see cref="IDataRowProvider"/>. Used to produce a list of objects when that type is an abstraction using a derived type. /// </summary> /// <typeparam name="T">The type of object represented by the lookup.</typeparam> /// <typeparam name="T2">The type of object represented by the lookup. The type must have an eligible constructor accepting <see cref="System.Data.DataRow"/> as its first parameter, and <see cref="System.Collections.Generic.IEnumerable{T}"/> of type <see cref="IAlias"/> as its second, and must be derived from T.</typeparam> /// <param name="dataRowProvider">The <see cref="IDataRowProvider"/> used to submit query.</param> /// <param name="dataOrder">The information for the query.</param> /// <returns>A <see cref='Task'/> with a result of <see cref="Utilities.OperationResult{T}"/> containing result upon success, and Exceptions upon failure.</returns> public static async Task <OperationResult <List <T> > > GetTableAsync <T, T2>(this IDataRowProvider dataRowProvider, IAliasedCommandTypeDataOrder dataOrder) where T2 : T { ConstructorInfo constructor = typeof(T2).GetConstructor(new[] { typeof(DataRow), typeof(IEnumerable <IAlias>) }); System.Diagnostics.Debug.Assert(constructor != null, "This overload can only be used with a Type that has an eligible constructor, which is one that accepts System.Data.DataRow as its first parameter, and System.Collections.Generic.IEnumerable<CSharpToolkit.Utilities.Abstractions.IAlias> for its second."); var operation = await dataRowProvider.SubmitQueryWithDataOrderAsync(dataOrder); return(operation.HadErrors ? new OperationResult <List <T> >(operation.Exceptions) : new OperationResult <List <T> >(await Task.Run(() => operation.Result.Select(r => (T2)constructor.Invoke(new object[] { r, dataOrder.Aliases })).Cast <T>().ToList()))); }