Skip to content

Commit

Permalink
Rename datareader extension methods from "To..." to "Read..." to avoi…
Browse files Browse the repository at this point in the history
…d conflicts with Linq extension methods names
  • Loading branch information
busterwood committed Mar 18, 2016
1 parent b5ddd0d commit 8f6f515
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 58 deletions.
40 changes: 20 additions & 20 deletions Mapper/CommandExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,117 +17,117 @@ public static class DbCommandExtensions

/// <summary>Executes the <paramref name="cmd"/> reading exactly one item</summary>
/// <exception cref="InvalidOperationException"> when zero values read or more than one value can be read</exception>
public static T ReadSingle<T>(this IDbCommand cmd)
public static T ExecuteSingle<T>(this IDbCommand cmd)
{
Contract.Requires(cmd != null);
Contract.Ensures(Contract.Result<T>() != null);
using (var reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
{
return reader.Single<T>();
return reader.ReadSingle<T>();
}
}

/// <summary>Executes the <paramref name="cmd"/> reading exactly one item</summary>
/// <exception cref="InvalidOperationException"> when zero values read or more than one value can be read</exception>
public static async Task<T> ReadSingleAsync<T>(this SqlCommand cmd)
public static async Task<T> ExecuteSingleAsync<T>(this SqlCommand cmd)
{
Contract.Requires(cmd != null);
Contract.Ensures(Contract.Result<T>() != null);
using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleRow))
{
return await reader.SingleAsync<T>();
return await reader.ReadSingleAsync<T>();
}
}

/// <summary>Executes the <paramref name="cmd"/> reading one item</summary>
/// <remarks>Returns the default vaue of T if no values be read, i.e may return null</remarks>
public static T ReadSingleOrDefault<T>(this IDbCommand cmd)
public static T ExecuteSingleOrDefault<T>(this IDbCommand cmd)
{
Contract.Requires(cmd != null);
using (var reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
{
return reader.SingleOrDefault<T>();
return reader.ReadSingleOrDefault<T>();
}
}

/// <summary>Executes the <paramref name="cmd"/> reading one item</summary>
/// <remarks>Returns the default vaue of T if no values be read, i.e may return null</remarks>
public static async Task<T> ReadSingleOrDefaultAsync<T>(this SqlCommand cmd)
public static async Task<T> ExecuteSingleOrDefaultAsync<T>(this SqlCommand cmd)
{
Contract.Requires(cmd != null);
using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleRow))
{
return await reader.SingleOrDefaultAsync<T>();
return await reader.ReadSingleOrDefaultAsync<T>();
}
}

/// <summary>Executes the <paramref name="cmd"/> and reads all the records into a list</summary>
public static List<T> ReadList<T>(this IDbCommand cmd)
public static List<T> ExecuteList<T>(this IDbCommand cmd)
{
Contract.Requires(cmd != null);
Contract.Ensures(Contract.Result<List<T>>() != null);
using (var reader = cmd.ExecuteReader())
{
return reader.ToList<T>();
return reader.ReadList<T>();
}
}

/// <summary>Executes the <paramref name="cmd"/> and reads all the records into a list</summary>
public static async Task<List<T>> ReadListAsync<T>(this SqlCommand cmd)
public static async Task<List<T>> ExecuteListAsync<T>(this SqlCommand cmd)
{
Contract.Requires(cmd != null);
Contract.Ensures(Contract.Result<List<T>>() != null);
using (var reader = await cmd.ExecuteReaderAsync())
{
return await reader.ToListAsync<T>();
return await reader.ReadListAsync<T>();
}
}

/// <summary>Executes the <paramref name="cmd"/> and reads all the records into a dictionary, using the supplied <paramref name="keyFunc"/> to generate the key</summary>
public static Dictionary<TKey, TValue> ReadDictionary<TKey, TValue>(this IDbCommand cmd, Func<TValue, TKey> keyFunc)
public static Dictionary<TKey, TValue> ExecuteDictionary<TKey, TValue>(this IDbCommand cmd, Func<TValue, TKey> keyFunc)
{
Contract.Requires(cmd != null);
Contract.Requires(keyFunc != null);
Contract.Ensures(Contract.Result<Dictionary<TKey, TValue>>() != null);
using (var reader = cmd.ExecuteReader())
{
return reader.ToDictionary(keyFunc);
return reader.ReadDictionary(keyFunc);
}
}

/// <summary>Executes the <paramref name="cmd"/> and reads all the records into a dictionary, using the supplied <paramref name="keyFunc"/> to generate the key</summary>
public static async Task<Dictionary<TKey, TValue>> ReadDictionaryAsync<TKey, TValue>(this SqlCommand cmd, Func<TValue, TKey> keyFunc)
public static async Task<Dictionary<TKey, TValue>> ExecuteDictionaryAsync<TKey, TValue>(this SqlCommand cmd, Func<TValue, TKey> keyFunc)
{
Contract.Requires(cmd != null);
Contract.Requires(keyFunc != null);
Contract.Ensures(Contract.Result<Dictionary<TKey, TValue>>() != null);
using (var reader = await cmd.ExecuteReaderAsync())
{
return await reader.ToDictionaryAsync(keyFunc);
return await reader.ReadDictionaryAsync(keyFunc);
}
}

/// <summary>Executes the <paramref name="cmd"/> and reads all the records in a lookup, grouped by key, using the supplied <paramref name="keyFunc"/> to generate the key</summary>
public static HashLookup<TKey, TValue> ReadLookup<TKey, TValue>(this IDbCommand cmd, Func<TValue, TKey> keyFunc)
public static HashLookup<TKey, TValue> ExecuteLookup<TKey, TValue>(this IDbCommand cmd, Func<TValue, TKey> keyFunc)
{
Contract.Requires(cmd != null);
Contract.Requires(keyFunc != null);
Contract.Ensures(Contract.Result<HashLookup<TKey, TValue>>() != null);
using (var reader = cmd.ExecuteReader())
{
return reader.ToLookup(keyFunc);
return reader.ReadLookup(keyFunc);
}
}

/// <summary>Executes the <paramref name="cmd"/> and reads all the records in a lookup, grouped by key, using the supplied <paramref name="keyFunc"/> to generate the key</summary>
public static async Task<HashLookup<TKey, TValue>> ReadLookupAsync<TKey, TValue>(this SqlCommand cmd, Func<TValue, TKey> keyFunc)
public static async Task<HashLookup<TKey, TValue>> ExecuteLookupAsync<TKey, TValue>(this SqlCommand cmd, Func<TValue, TKey> keyFunc)
{
Contract.Requires(cmd != null);
Contract.Requires(keyFunc != null);
Contract.Ensures(Contract.Result<HashLookup<TKey, TValue>>() != null);
using (var reader = await cmd.ExecuteReaderAsync())
{
return await reader.ToLookupAsync(keyFunc);
return await reader.ReadLookupAsync(keyFunc);
}
}

Expand Down
28 changes: 14 additions & 14 deletions Mapper/ConnectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static T QuerySingle<T>(this IDbConnection cnn, string sql, object parame
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, parameters);
return cmd.ReadSingle<T>();
return cmd.ExecuteSingle<T>();
}
}

Expand All @@ -59,7 +59,7 @@ public static Task<T> QuerySingleAsync<T>(this SqlConnection cnn, string sql, ob
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, parameters);
return cmd.ReadSingleAsync<T>();
return cmd.ExecuteSingleAsync<T>();
}
}

Expand All @@ -71,7 +71,7 @@ public static T QuerySingleOrDefault<T>(this IDbConnection cnn, string sql, obje
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, parameters);
return cmd.ReadSingleOrDefault<T>();
return cmd.ExecuteSingleOrDefault<T>();
}
}

Expand All @@ -83,7 +83,7 @@ public static Task<T> QuerySingleOrDefaultAsync<T>(this SqlConnection cnn, strin
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, parameters);
return cmd.ReadSingleOrDefaultAsync<T>();
return cmd.ExecuteSingleOrDefaultAsync<T>();
}
}

Expand All @@ -97,7 +97,7 @@ public static List<T> QueryList<T>(this IDbConnection cnn, string sql, object pa
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, parameters);
return cmd.ReadList<T>();
return cmd.ExecuteList<T>();
}
}

Expand All @@ -111,7 +111,7 @@ public static Task<List<T>> QueryListAsync<T>(this SqlConnection cnn, string sql
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, parameters);
return cmd.ReadListAsync<T>();
return cmd.ExecuteListAsync<T>();
}
}

Expand All @@ -126,7 +126,7 @@ public static Dictionary<TKey, TValue> QueryDictionary<TKey, TValue>(this IDbCon
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, null);
return cmd.ReadDictionary(keyFunc);
return cmd.ExecuteDictionary(keyFunc);
}
}

Expand All @@ -141,7 +141,7 @@ public static Task<Dictionary<TKey, TValue>> QueryDictionaryAsync<TKey, TValue>(
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, null);
return cmd.ReadDictionaryAsync(keyFunc);
return cmd.ExecuteDictionaryAsync(keyFunc);
}
}

Expand All @@ -157,7 +157,7 @@ public static Dictionary<TKey, TValue> QueryDictionary<TKey, TValue>(this IDbCon
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, parameters);
return cmd.ReadDictionary(keyFunc);
return cmd.ExecuteDictionary(keyFunc);
}
}

Expand All @@ -173,7 +173,7 @@ public static Task<Dictionary<TKey, TValue>> QueryDictionaryAsync<TKey, TValue>(
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, parameters);
return cmd.ReadDictionaryAsync(keyFunc);
return cmd.ExecuteDictionaryAsync(keyFunc);
}
}

Expand All @@ -188,7 +188,7 @@ public static ILookup<TKey, TValue> QueryLookup<TKey, TValue>(this IDbConnection
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, null);
return cmd.ReadLookup(keyFunc);
return cmd.ExecuteLookup(keyFunc);
}
}

Expand All @@ -204,7 +204,7 @@ public static ILookup<TKey, TValue> QueryLookup<TKey, TValue>(this IDbConnection
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, parameters);
return cmd.ReadLookup(keyFunc);
return cmd.ExecuteLookup(keyFunc);
}
}

Expand All @@ -219,7 +219,7 @@ public static async Task<HashLookup<TKey, TValue>> QueryLookupAsync<TKey, TValue
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, null);
return await cmd.ReadLookupAsync(keyFunc);
return await cmd.ExecuteLookupAsync(keyFunc);
}
}

Expand All @@ -235,7 +235,7 @@ public static async Task<HashLookup<TKey, TValue>> QueryLookupAsync<TKey, TValue
using (var cmd = cnn.CreateCommand())
{
SetupCommand(cmd, cnn, sql, parameters);
return await cmd.ReadLookupAsync(keyFunc);
return await cmd.ExecuteLookupAsync(keyFunc);
}
}

Expand Down
21 changes: 10 additions & 11 deletions Mapper/DataReaderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class DataReaderExtensions

/// <summary>Reads exactly one item from the reader</summary>
/// <exception cref="InvalidOperationException"> when zero values read or more than one value can be read</exception>
public static T Single<T>(this IDataReader reader)
public static T ReadSingle<T>(this IDataReader reader)
{
Contract.Requires(reader != null);
Contract.Requires(reader.IsClosed == false);
Expand All @@ -30,7 +30,7 @@ public static T Single<T>(this IDataReader reader)

/// <summary>Reads exactly one item from the reader</summary>
/// <exception cref="InvalidOperationException"> when zero values read or more than one value can be read</exception>
public static async Task<T> SingleAsync<T>(this SqlDataReader reader)
public static async Task<T> ReadSingleAsync<T>(this SqlDataReader reader)
{
Contract.Requires(reader != null);
Contract.Requires(reader.IsClosed == false);
Expand All @@ -44,7 +44,7 @@ public static async Task<T> SingleAsync<T>(this SqlDataReader reader)

/// <summary>Reads zero or one items from the reader</summary>
/// <remarks>Returns the default vaue of T if no values be read, i.e may return null</remarks>
public static T SingleOrDefault<T>(this IDataReader reader)
public static T ReadSingleOrDefault<T>(this IDataReader reader)
{
Contract.Requires(reader != null);
Contract.Requires(reader.IsClosed == false);
Expand All @@ -55,7 +55,7 @@ public static T SingleOrDefault<T>(this IDataReader reader)

/// <summary>Reads zero or one items from the reader</summary>
/// <remarks>Returns the default vaue of T if no values be read, i.e may return null</remarks>
public static async Task<T> SingleOrDefaultAsync<T>(this SqlDataReader reader)
public static async Task<T> ReadSingleOrDefaultAsync<T>(this SqlDataReader reader)
{
Contract.Requires(reader != null);
Contract.Requires(reader.IsClosed == false);
Expand All @@ -65,7 +65,7 @@ public static async Task<T> SingleOrDefaultAsync<T>(this SqlDataReader reader)
}

/// <summary>Reads all the records in the reader into a list</summary>
public static List<T> ToList<T>(this IDataReader reader)
public static List<T> ReadList<T>(this IDataReader reader)
{
Contract.Requires(reader != null);
Contract.Requires(reader.IsClosed == false);
Expand All @@ -80,7 +80,7 @@ public static List<T> ToList<T>(this IDataReader reader)
}

/// <summary>Reads all the records in the reader into a list</summary>
public static async Task<List<T>> ToListAsync<T>(this SqlDataReader reader)
public static async Task<List<T>> ReadListAsync<T>(this SqlDataReader reader)
{
Contract.Requires(reader != null);
Contract.Requires(reader.IsClosed == false);
Expand All @@ -95,7 +95,7 @@ public static async Task<List<T>> ToListAsync<T>(this SqlDataReader reader)
}

/// <summary>Reads all the records in the reader into a dictionary, using the supplied <paramref name="keyFunc"/> to generate the key</summary>
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IDataReader reader, Func<TValue, TKey> keyFunc)
public static Dictionary<TKey, TValue> ReadDictionary<TKey, TValue>(this IDataReader reader, Func<TValue, TKey> keyFunc)
{
Contract.Requires(reader != null);
Contract.Requires(keyFunc != null);
Expand All @@ -113,7 +113,7 @@ public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IDataRead
}

/// <summary>Reads all the records in the reader into a dictionary, using the supplied <paramref name="keyFunc"/> to generate the key</summary>
public static async Task<Dictionary<TKey, TValue>> ToDictionaryAsync<TKey, TValue>(this SqlDataReader reader, Func<TValue, TKey> keyFunc)
public static async Task<Dictionary<TKey, TValue>> ReadDictionaryAsync<TKey, TValue>(this SqlDataReader reader, Func<TValue, TKey> keyFunc)
{
Contract.Requires(reader != null);
Contract.Requires(keyFunc != null);
Expand All @@ -131,7 +131,7 @@ public static async Task<Dictionary<TKey, TValue>> ToDictionaryAsync<TKey, TValu
}

/// <summary>Reads all the records in the lookup, group by key, using the supplied <paramref name="keyFunc"/> to generate the key</summary>
public static HashLookup<TKey, TValue> ToLookup<TKey, TValue>(this IDataReader reader, Func<TValue, TKey> keyFunc)
public static HashLookup<TKey, TValue> ReadLookup<TKey, TValue>(this IDataReader reader, Func<TValue, TKey> keyFunc)
{
Contract.Requires(reader != null);
Contract.Requires(keyFunc != null);
Expand All @@ -148,7 +148,7 @@ public static HashLookup<TKey, TValue> ToLookup<TKey, TValue>(this IDataReader r
}

/// <summary>Reads all the records in the lookup, group by key, using the supplied <paramref name="keyFunc"/> to generate the key</summary>
public static async Task<HashLookup<TKey, TValue>> ToLookupAsync<TKey, TValue>(this SqlDataReader reader, Func<TValue, TKey> keyFunc)
public static async Task<HashLookup<TKey, TValue>> ReadLookupAsync<TKey, TValue>(this SqlDataReader reader, Func<TValue, TKey> keyFunc)
{
Contract.Requires(reader != null);
Contract.Requires(keyFunc != null);
Expand All @@ -164,7 +164,6 @@ public static async Task<HashLookup<TKey, TValue>> ToLookupAsync<TKey, TValue>(t
return lookup;
}


private static Func<IDataReader, T> GetMappingFunc<T>(IDataReader reader)
{
var columns = CreateColumnList(reader);
Expand Down
2 changes: 1 addition & 1 deletion Mapper/Mapper.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Mapper</id>
<version>1.0.1.5</version>
<version>1.0.2.0</version>
<authors>BusterWood</authors>
<description>A convention-based object cloner, object-object mapper (like AutoMapper), IDataReader to object mapper, object to IDbDataParameter mapper, etc.</description>
<projectUrl>https://github.com/busterwood/mapper</projectUrl>
Expand Down
4 changes: 2 additions & 2 deletions Mapper/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.1.5")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]

[assembly: InternalsVisibleTo("Mapper.UnitTests")]
Loading

0 comments on commit 8f6f515

Please sign in to comment.