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
{
public static partial class SqlMapper
{
/// <summary>
/// Execute a query asynchronously using .NET 4.5 Task.
/// </summary>
......@@ -112,8 +111,6 @@ private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn,
{
buffer.Add((T)Convert.ChangeType(val, convertToType, CultureInfo.InvariantCulture));
}
}
while (await reader.NextResultAsync(cancel).ConfigureAwait(false)) { }
command.OnCompleted();
......@@ -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
return deferred;
}
}
finally
{
......@@ -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)
{
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);
bool wasClosed = cnn.State == ConnectionState.Closed;
try
......
......@@ -7,7 +7,6 @@ namespace Dapper
{
partial class SqlMapper
{
private sealed class DapperRow
: System.Dynamic.IDynamicMetaObjectProvider
, IDictionary<string, object>
......@@ -171,6 +170,7 @@ public object SetValue(string key, object value)
{
return SetValue(key, value, false);
}
private object SetValue(string key, object value, bool isAdd)
{
if (key == null) throw new ArgumentNullException(nameof(key));
......
......@@ -42,14 +42,9 @@ internal int AddField(string name)
return oldLen;
}
internal bool FieldExists(string key)
{
return key != null && fieldNameLookup.ContainsKey(key);
}
internal bool FieldExists(string key) => key != null && fieldNameLookup.ContainsKey(key);
public int FieldCount => fieldNames.Length;
}
}
}
......@@ -12,7 +12,6 @@ namespace Dapper
{
partial class SqlMapper
{
/// <summary>
/// The grid reader provides interfaces for reading multiple result sets from a Dapper query
/// </summary>
......
......@@ -35,6 +35,5 @@ public interface IMemberMap
/// </summary>
ParameterInfo Parameter { get; }
}
}
}
......@@ -2,7 +2,6 @@
{
partial class SqlMapper
{
/// <summary>
/// Extends IDynamicParameters with facilities for executing callbacks after commands have completed
/// </summary>
......@@ -13,6 +12,5 @@ public interface IParameterCallbacks : IDynamicParameters
/// </summary>
void OnCompleted();
}
}
}
......@@ -42,6 +42,5 @@ public interface ITypeMap
/// <returns>Mapping implementation</returns>
IMemberMap GetMember(string columnName);
}
}
}
......@@ -25,6 +25,5 @@ public static void SetDefaults()
/// </summary>
public static int? CommandTimeout { get; set; }
}
}
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
#if COREFX
using IDbDataParameter = System.Data.Common.DbParameter;
......@@ -48,6 +45,5 @@ object ITypeHandler.Parse(Type destinationType, object value)
return Parse(value);
}
}
}
}
......@@ -27,7 +27,6 @@ public static class TypeHandlerCache<T>
public static T Parse(object value)
{
return (T)handler.Parse(typeof(T), value);
}
/// <summary>
......
......@@ -311,8 +311,6 @@ public static void AddTypeHandler<T>(TypeHandler<T> handler)
AddTypeHandlerImpl(typeof(T), handler, true);
}
private static Dictionary<Type, ITypeHandler> typeHandlers = new Dictionary<Type, ITypeHandler>();
internal const string LinqBinary = "System.Data.Linq.Binary";
......@@ -1001,7 +999,7 @@ static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn, Comman
}
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);
IDbCommand ownedCommand = null;
......@@ -1018,7 +1016,7 @@ static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn, Comman
reader = ownedReader;
}
DeserializerState deserializer = default(DeserializerState);
Func<IDataReader, object>[] otherDeserializers = null;
Func<IDataReader, object>[] otherDeserializers;
int hash = GetColumnHash(reader);
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
var deserializers = new List<Func<IDataReader, object>>();
var splits = splitOn.Split(',').Select(s => s.Trim()).ToArray();
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
// is supported
......@@ -1318,8 +1316,7 @@ private static void PassByPosition(IDbCommand cmd)
}
static Func<IDataReader, object> GetHandlerDeserializer(ITypeHandler handler, Type type, int startBound)
{
return (IDataReader reader) =>
handler.Parse(type, reader.GetValue(startBound));
return reader => handler.Parse(type, reader.GetValue(startBound));
}
......@@ -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
)
{
var dm = new DynamicMethod($"Deserialize{Guid.NewGuid()}", typeof(object), new[] { typeof(IDataReader) }, true);
var il = dm.GetILGenerator();
il.DeclareLocal(typeof(int));
......@@ -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]
}
}
}
}
if (specializedConstructor == null)
......@@ -2747,8 +2741,8 @@ static MethodInfo GetOperator(Type from, Type to)
?? ResolveOperator(toMethods = to.GetMethods(BindingFlags.Static | BindingFlags.Public), from, to, "op_Implicit")
?? ResolveOperator(fromMethods, from, to, "op_Explicit")
?? ResolveOperator(toMethods, from, to, "op_Explicit");
}
static MethodInfo ResolveOperator(MethodInfo[] methods, Type from, Type to, string name)
{
for (int i = 0; i < methods.Length; i++)
......@@ -2803,6 +2797,7 @@ private static void StoreLocal(ILGenerator il, int index)
break;
}
}
private static void LoadLocalAddress(ILGenerator il, int index)
{
if (index < 0 || index >= short.MaxValue) throw new ArgumentNullException(nameof(index));
......@@ -2816,6 +2811,7 @@ private static void LoadLocalAddress(ILGenerator il, int index)
il.Emit(OpCodes.Ldloca, (short)index);
}
}
/// <summary>
/// Throws a data exception, only used internally
/// </summary>
......@@ -2853,6 +2849,7 @@ public static void ThrowDataException(Exception ex, int index, IDataReader reade
}
throw toThrow;
}
private static void EmitInt32(ILGenerator il, int value)
{
switch (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>
/// 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
......@@ -2899,10 +2890,12 @@ public static IEqualityComparer<string> ConnectionStringComparer
}
private static IEqualityComparer<string> connectionStringComparer = StringComparer.Ordinal;
#if !COREFX
/// <summary>
/// Key used to indicate the type name associated with a DataTable
/// </summary>
private const string DataTableTypeNameKey = "dapper:TypeName";
/// <summary>
/// Used to pass a DataTable as a TableValuedParameter
/// </summary>
......@@ -2969,7 +2962,4 @@ private static string __ToStringRecycle(this StringBuilder obj)
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