Commit d2ab2f8d authored by Nick Craver's avatar Nick Craver

Core: SqlMapper cleanup

Assuming the CHSARP30 were oversights here given the net35 removal, but
playing it safe and leaving for this commit.
parent 114bc107
...@@ -20,7 +20,6 @@ namespace Dapper ...@@ -20,7 +20,6 @@ namespace Dapper
{ {
public static partial class SqlMapper public static partial class SqlMapper
{ {
/// <summary> /// <summary>
/// Execute a query asynchronously using .NET 4.5 Task. /// Execute a query asynchronously using .NET 4.5 Task.
/// </summary> /// </summary>
...@@ -112,8 +111,6 @@ private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn, ...@@ -112,8 +111,6 @@ private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn,
{ {
buffer.Add((T)Convert.ChangeType(val, convertToType, CultureInfo.InvariantCulture)); buffer.Add((T)Convert.ChangeType(val, convertToType, CultureInfo.InvariantCulture));
} }
} }
while (await reader.NextResultAsync(cancel).ConfigureAwait(false)) { } while (await reader.NextResultAsync(cancel).ConfigureAwait(false)) { }
command.OnCompleted(); command.OnCompleted();
...@@ -127,7 +124,6 @@ private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn, ...@@ -127,7 +124,6 @@ private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn,
reader = null; // to prevent it being disposed before the caller gets to see it reader = null; // to prevent it being disposed before the caller gets to see it
return deferred; return deferred;
} }
} }
finally finally
{ {
...@@ -461,7 +457,7 @@ private static async Task<int> ExecuteImplAsync(IDbConnection cnn, CommandDefini ...@@ -461,7 +457,7 @@ private static async Task<int> ExecuteImplAsync(IDbConnection cnn, CommandDefini
private static async Task<IEnumerable<TReturn>> MultiMapAsync<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(this IDbConnection cnn, CommandDefinition command, Delegate map, string splitOn) private static async Task<IEnumerable<TReturn>> MultiMapAsync<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(this IDbConnection cnn, CommandDefinition command, Delegate map, string splitOn)
{ {
object param = command.Parameters; object param = command.Parameters;
var identity = new Identity(command.CommandText, command.CommandType, cnn, typeof(TFirst), param == null ? null : param.GetType(), new[] { typeof(TFirst), typeof(TSecond), typeof(TThird), typeof(TFourth), typeof(TFifth), typeof(TSixth), typeof(TSeventh) }); var identity = new Identity(command.CommandText, command.CommandType, cnn, typeof(TFirst), param?.GetType(), new[] { typeof(TFirst), typeof(TSecond), typeof(TThird), typeof(TFourth), typeof(TFifth), typeof(TSixth), typeof(TSeventh) });
var info = GetCacheInfo(identity, param, command.AddToCache); var info = GetCacheInfo(identity, param, command.AddToCache);
bool wasClosed = cnn.State == ConnectionState.Closed; bool wasClosed = cnn.State == ConnectionState.Closed;
try try
......
...@@ -7,7 +7,6 @@ namespace Dapper ...@@ -7,7 +7,6 @@ namespace Dapper
{ {
partial class SqlMapper partial class SqlMapper
{ {
private sealed class DapperRow private sealed class DapperRow
: System.Dynamic.IDynamicMetaObjectProvider : System.Dynamic.IDynamicMetaObjectProvider
, IDictionary<string, object> , IDictionary<string, object>
...@@ -171,6 +170,7 @@ public object SetValue(string key, object value) ...@@ -171,6 +170,7 @@ public object SetValue(string key, object value)
{ {
return SetValue(key, value, false); return SetValue(key, value, false);
} }
private object SetValue(string key, object value, bool isAdd) private object SetValue(string key, object value, bool isAdd)
{ {
if (key == null) throw new ArgumentNullException(nameof(key)); if (key == null) throw new ArgumentNullException(nameof(key));
......
...@@ -41,15 +41,10 @@ internal int AddField(string name) ...@@ -41,15 +41,10 @@ internal int AddField(string name)
fieldNameLookup[name] = oldLen; fieldNameLookup[name] = oldLen;
return oldLen; return oldLen;
} }
internal bool FieldExists(string key) => key != null && fieldNameLookup.ContainsKey(key);
internal bool FieldExists(string key)
{
return key != null && fieldNameLookup.ContainsKey(key);
}
public int FieldCount => fieldNames.Length; public int FieldCount => fieldNames.Length;
} }
} }
} }
...@@ -12,7 +12,6 @@ namespace Dapper ...@@ -12,7 +12,6 @@ namespace Dapper
{ {
partial class SqlMapper partial class SqlMapper
{ {
/// <summary> /// <summary>
/// The grid reader provides interfaces for reading multiple result sets from a Dapper query /// The grid reader provides interfaces for reading multiple result sets from a Dapper query
/// </summary> /// </summary>
......
...@@ -35,6 +35,5 @@ public interface IMemberMap ...@@ -35,6 +35,5 @@ public interface IMemberMap
/// </summary> /// </summary>
ParameterInfo Parameter { get; } ParameterInfo Parameter { get; }
} }
} }
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
{ {
partial class SqlMapper partial class SqlMapper
{ {
/// <summary> /// <summary>
/// Extends IDynamicParameters with facilities for executing callbacks after commands have completed /// Extends IDynamicParameters with facilities for executing callbacks after commands have completed
/// </summary> /// </summary>
...@@ -13,6 +12,5 @@ public interface IParameterCallbacks : IDynamicParameters ...@@ -13,6 +12,5 @@ public interface IParameterCallbacks : IDynamicParameters
/// </summary> /// </summary>
void OnCompleted(); void OnCompleted();
} }
} }
} }
...@@ -42,6 +42,5 @@ public interface ITypeMap ...@@ -42,6 +42,5 @@ public interface ITypeMap
/// <returns>Mapping implementation</returns> /// <returns>Mapping implementation</returns>
IMemberMap GetMember(string columnName); IMemberMap GetMember(string columnName);
} }
} }
} }
...@@ -25,6 +25,5 @@ public static void SetDefaults() ...@@ -25,6 +25,5 @@ public static void SetDefaults()
/// </summary> /// </summary>
public static int? CommandTimeout { get; set; } public static int? CommandTimeout { get; set; }
} }
} }
} }
using System; using System;
using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq;
using System.Text;
#if COREFX #if COREFX
using IDbDataParameter = System.Data.Common.DbParameter; using IDbDataParameter = System.Data.Common.DbParameter;
...@@ -48,6 +45,5 @@ object ITypeHandler.Parse(Type destinationType, object value) ...@@ -48,6 +45,5 @@ object ITypeHandler.Parse(Type destinationType, object value)
return Parse(value); return Parse(value);
} }
} }
} }
} }
...@@ -27,7 +27,6 @@ public static class TypeHandlerCache<T> ...@@ -27,7 +27,6 @@ public static class TypeHandlerCache<T>
public static T Parse(object value) public static T Parse(object value)
{ {
return (T)handler.Parse(typeof(T), value); return (T)handler.Parse(typeof(T), value);
} }
/// <summary> /// <summary>
......
...@@ -310,9 +310,7 @@ public static void AddTypeHandler<T>(TypeHandler<T> handler) ...@@ -310,9 +310,7 @@ public static void AddTypeHandler<T>(TypeHandler<T> handler)
{ {
AddTypeHandlerImpl(typeof(T), handler, true); AddTypeHandlerImpl(typeof(T), handler, true);
} }
private static Dictionary<Type, ITypeHandler> typeHandlers = new Dictionary<Type, ITypeHandler>(); private static Dictionary<Type, ITypeHandler> typeHandlers = new Dictionary<Type, ITypeHandler>();
internal const string LinqBinary = "System.Data.Linq.Binary"; internal const string LinqBinary = "System.Data.Linq.Binary";
...@@ -1001,7 +999,7 @@ static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn, Comman ...@@ -1001,7 +999,7 @@ static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn, Comman
} }
object param = command.Parameters; object param = command.Parameters;
identity = identity ?? new Identity(command.CommandText, command.CommandType, cnn, types[0], param == null ? null : param.GetType(), types); identity = identity ?? new Identity(command.CommandText, command.CommandType, cnn, types[0], param?.GetType(), types);
CacheInfo cinfo = GetCacheInfo(identity, param, command.AddToCache); CacheInfo cinfo = GetCacheInfo(identity, param, command.AddToCache);
IDbCommand ownedCommand = null; IDbCommand ownedCommand = null;
...@@ -1018,7 +1016,7 @@ static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn, Comman ...@@ -1018,7 +1016,7 @@ static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn, Comman
reader = ownedReader; reader = ownedReader;
} }
DeserializerState deserializer = default(DeserializerState); DeserializerState deserializer = default(DeserializerState);
Func<IDataReader, object>[] otherDeserializers = null; Func<IDataReader, object>[] otherDeserializers;
int hash = GetColumnHash(reader); int hash = GetColumnHash(reader);
if ((deserializer = cinfo.Deserializer).Func == null || (otherDeserializers = cinfo.OtherDeserializers) == null || hash != deserializer.Hash) if ((deserializer = cinfo.Deserializer).Func == null || (otherDeserializers = cinfo.OtherDeserializers) == null || hash != deserializer.Hash)
...@@ -1100,7 +1098,7 @@ static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn, Comman ...@@ -1100,7 +1098,7 @@ static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn, Comman
var deserializers = new List<Func<IDataReader, object>>(); var deserializers = new List<Func<IDataReader, object>>();
var splits = splitOn.Split(',').Select(s => s.Trim()).ToArray(); var splits = splitOn.Split(',').Select(s => s.Trim()).ToArray();
bool isMultiSplit = splits.Length > 1; bool isMultiSplit = splits.Length > 1;
if (types.First() == typeof(Object)) if (types.First() == typeof(object))
{ {
// we go left to right for dynamic multi-mapping so that the madness of TestMultiMappingVariations // we go left to right for dynamic multi-mapping so that the madness of TestMultiMappingVariations
// is supported // is supported
...@@ -1318,8 +1316,7 @@ private static void PassByPosition(IDbCommand cmd) ...@@ -1318,8 +1316,7 @@ private static void PassByPosition(IDbCommand cmd)
} }
static Func<IDataReader, object> GetHandlerDeserializer(ITypeHandler handler, Type type, int startBound) static Func<IDataReader, object> GetHandlerDeserializer(ITypeHandler handler, Type type, int startBound)
{ {
return (IDataReader reader) => return reader => handler.Parse(type, reader.GetValue(startBound));
handler.Parse(type, reader.GetValue(startBound));
} }
...@@ -2344,7 +2341,6 @@ public static void SetTypeMap(Type type, ITypeMap map) ...@@ -2344,7 +2341,6 @@ public static void SetTypeMap(Type type, ITypeMap map)
Type type, IDataReader reader, int startBound = 0, int length = -1, bool returnNullIfFirstMissing = false Type type, IDataReader reader, int startBound = 0, int length = -1, bool returnNullIfFirstMissing = false
) )
{ {
var dm = new DynamicMethod($"Deserialize{Guid.NewGuid()}", typeof(object), new[] { typeof(IDataReader) }, true); var dm = new DynamicMethod($"Deserialize{Guid.NewGuid()}", typeof(object), new[] { typeof(IDataReader) }, true);
var il = dm.GetILGenerator(); var il = dm.GetILGenerator();
il.DeclareLocal(typeof(int)); il.DeclareLocal(typeof(int));
...@@ -2565,9 +2561,7 @@ public static void SetTypeMap(Type type, ITypeMap map) ...@@ -2565,9 +2561,7 @@ public static void SetTypeMap(Type type, ITypeMap map)
{ {
il.Emit(OpCodes.Newobj, unboxType.GetConstructor(new[] { nullUnderlyingType })); // stack is now [target][target][typed-value] il.Emit(OpCodes.Newobj, unboxType.GetConstructor(new[] { nullUnderlyingType })); // stack is now [target][target][typed-value]
} }
} }
} }
} }
if (specializedConstructor == null) if (specializedConstructor == null)
...@@ -2747,8 +2741,8 @@ static MethodInfo GetOperator(Type from, Type to) ...@@ -2747,8 +2741,8 @@ static MethodInfo GetOperator(Type from, Type to)
?? ResolveOperator(toMethods = to.GetMethods(BindingFlags.Static | BindingFlags.Public), from, to, "op_Implicit") ?? ResolveOperator(toMethods = to.GetMethods(BindingFlags.Static | BindingFlags.Public), from, to, "op_Implicit")
?? ResolveOperator(fromMethods, from, to, "op_Explicit") ?? ResolveOperator(fromMethods, from, to, "op_Explicit")
?? ResolveOperator(toMethods, from, to, "op_Explicit"); ?? ResolveOperator(toMethods, from, to, "op_Explicit");
} }
static MethodInfo ResolveOperator(MethodInfo[] methods, Type from, Type to, string name) static MethodInfo ResolveOperator(MethodInfo[] methods, Type from, Type to, string name)
{ {
for (int i = 0; i < methods.Length; i++) for (int i = 0; i < methods.Length; i++)
...@@ -2803,6 +2797,7 @@ private static void StoreLocal(ILGenerator il, int index) ...@@ -2803,6 +2797,7 @@ private static void StoreLocal(ILGenerator il, int index)
break; break;
} }
} }
private static void LoadLocalAddress(ILGenerator il, int index) private static void LoadLocalAddress(ILGenerator il, int index)
{ {
if (index < 0 || index >= short.MaxValue) throw new ArgumentNullException(nameof(index)); if (index < 0 || index >= short.MaxValue) throw new ArgumentNullException(nameof(index));
...@@ -2816,6 +2811,7 @@ private static void LoadLocalAddress(ILGenerator il, int index) ...@@ -2816,6 +2811,7 @@ private static void LoadLocalAddress(ILGenerator il, int index)
il.Emit(OpCodes.Ldloca, (short)index); il.Emit(OpCodes.Ldloca, (short)index);
} }
} }
/// <summary> /// <summary>
/// Throws a data exception, only used internally /// Throws a data exception, only used internally
/// </summary> /// </summary>
...@@ -2853,6 +2849,7 @@ public static void ThrowDataException(Exception ex, int index, IDataReader reade ...@@ -2853,6 +2849,7 @@ public static void ThrowDataException(Exception ex, int index, IDataReader reade
} }
throw toThrow; throw toThrow;
} }
private static void EmitInt32(ILGenerator il, int value) private static void EmitInt32(ILGenerator il, int value)
{ {
switch (value) switch (value)
...@@ -2880,12 +2877,6 @@ private static void EmitInt32(ILGenerator il, int value) ...@@ -2880,12 +2877,6 @@ private static void EmitInt32(ILGenerator il, int value)
} }
} }
/// <summary>
/// Key used to indicate the type name associated with a DataTable
/// </summary>
private const string DataTableTypeNameKey = "dapper:TypeName";
/// <summary> /// <summary>
/// How should connection strings be compared for equivalence? Defaults to StringComparer.Ordinal. /// How should connection strings be compared for equivalence? Defaults to StringComparer.Ordinal.
/// Providing a custom implementation can be useful for allowing multi-tenancy databases with identical /// Providing a custom implementation can be useful for allowing multi-tenancy databases with identical
...@@ -2899,10 +2890,12 @@ public static IEqualityComparer<string> ConnectionStringComparer ...@@ -2899,10 +2890,12 @@ public static IEqualityComparer<string> ConnectionStringComparer
} }
private static IEqualityComparer<string> connectionStringComparer = StringComparer.Ordinal; private static IEqualityComparer<string> connectionStringComparer = StringComparer.Ordinal;
#if !COREFX #if !COREFX
/// <summary>
/// Key used to indicate the type name associated with a DataTable
/// </summary>
private const string DataTableTypeNameKey = "dapper:TypeName";
/// <summary> /// <summary>
/// Used to pass a DataTable as a TableValuedParameter /// Used to pass a DataTable as a TableValuedParameter
/// </summary> /// </summary>
...@@ -2969,7 +2962,4 @@ private static string __ToStringRecycle(this StringBuilder obj) ...@@ -2969,7 +2962,4 @@ private static string __ToStringRecycle(this StringBuilder obj)
return s; return s;
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment