Commit d1b2e154 authored by mgravell's avatar mgravell

get rid of all the NS1.3 fallback code

parent 2f7081a3
...@@ -37,7 +37,7 @@ public static partial class SqlMapperExtensions ...@@ -37,7 +37,7 @@ public static partial class SqlMapperExtensions
var dynParms = new DynamicParameters(); var dynParms = new DynamicParameters();
dynParms.Add("@id", id); dynParms.Add("@id", id);
if (!type.IsInterface()) if (!type.IsInterface)
return (await connection.QueryAsync<T>(sql, dynParms, transaction, commandTimeout).ConfigureAwait(false)).FirstOrDefault(); return (await connection.QueryAsync<T>(sql, dynParms, transaction, commandTimeout).ConfigureAwait(false)).FirstOrDefault();
var res = (await connection.QueryAsync<dynamic>(sql, dynParms).ConfigureAwait(false)).FirstOrDefault() as IDictionary<string, object>; var res = (await connection.QueryAsync<dynamic>(sql, dynParms).ConfigureAwait(false)).FirstOrDefault() as IDictionary<string, object>;
...@@ -51,7 +51,7 @@ public static partial class SqlMapperExtensions ...@@ -51,7 +51,7 @@ public static partial class SqlMapperExtensions
{ {
var val = res[property.Name]; var val = res[property.Name];
if (val == null) continue; if (val == null) continue;
if (property.PropertyType.IsGenericType() && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{ {
var genericType = Nullable.GetUnderlyingType(property.PropertyType); var genericType = Nullable.GetUnderlyingType(property.PropertyType);
if (genericType != null) property.SetValue(obj, Convert.ChangeType(val, genericType), null); if (genericType != null) property.SetValue(obj, Convert.ChangeType(val, genericType), null);
...@@ -92,7 +92,7 @@ public static partial class SqlMapperExtensions ...@@ -92,7 +92,7 @@ public static partial class SqlMapperExtensions
GetQueries[cacheType.TypeHandle] = sql; GetQueries[cacheType.TypeHandle] = sql;
} }
if (!type.IsInterface()) if (!type.IsInterface)
{ {
return connection.QueryAsync<T>(sql, null, transaction, commandTimeout); return connection.QueryAsync<T>(sql, null, transaction, commandTimeout);
} }
...@@ -110,7 +110,7 @@ public static partial class SqlMapperExtensions ...@@ -110,7 +110,7 @@ public static partial class SqlMapperExtensions
{ {
var val = res[property.Name]; var val = res[property.Name];
if (val == null) continue; if (val == null) continue;
if (property.PropertyType.IsGenericType() && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{ {
var genericType = Nullable.GetUnderlyingType(property.PropertyType); var genericType = Nullable.GetUnderlyingType(property.PropertyType);
if (genericType != null) property.SetValue(obj, Convert.ChangeType(val, genericType), null); if (genericType != null) property.SetValue(obj, Convert.ChangeType(val, genericType), null);
...@@ -148,11 +148,11 @@ public static partial class SqlMapperExtensions ...@@ -148,11 +148,11 @@ public static partial class SqlMapperExtensions
isList = true; isList = true;
type = type.GetElementType(); type = type.GetElementType();
} }
else if (type.IsGenericType()) else if (type.IsGenericType)
{ {
var typeInfo = type.GetTypeInfo(); var typeInfo = type.GetTypeInfo();
bool implementsGenericIEnumerableOrIsGenericIEnumerable = bool implementsGenericIEnumerableOrIsGenericIEnumerable =
typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType() && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) || typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) ||
typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>); typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>);
if (implementsGenericIEnumerableOrIsGenericIEnumerable) if (implementsGenericIEnumerableOrIsGenericIEnumerable)
...@@ -219,11 +219,11 @@ public static partial class SqlMapperExtensions ...@@ -219,11 +219,11 @@ public static partial class SqlMapperExtensions
{ {
type = type.GetElementType(); type = type.GetElementType();
} }
else if (type.IsGenericType()) else if (type.IsGenericType)
{ {
var typeInfo = type.GetTypeInfo(); var typeInfo = type.GetTypeInfo();
bool implementsGenericIEnumerableOrIsGenericIEnumerable = bool implementsGenericIEnumerableOrIsGenericIEnumerable =
typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType() && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) || typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) ||
typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>); typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>);
if (implementsGenericIEnumerableOrIsGenericIEnumerable) if (implementsGenericIEnumerableOrIsGenericIEnumerable)
...@@ -288,11 +288,11 @@ public static partial class SqlMapperExtensions ...@@ -288,11 +288,11 @@ public static partial class SqlMapperExtensions
{ {
type = type.GetElementType(); type = type.GetElementType();
} }
else if (type.IsGenericType()) else if (type.IsGenericType)
{ {
var typeInfo = type.GetTypeInfo(); var typeInfo = type.GetTypeInfo();
bool implementsGenericIEnumerableOrIsGenericIEnumerable = bool implementsGenericIEnumerableOrIsGenericIEnumerable =
typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType() && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) || typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) ||
typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>); typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>);
if (implementsGenericIEnumerableOrIsGenericIEnumerable) if (implementsGenericIEnumerableOrIsGenericIEnumerable)
......
...@@ -190,7 +190,7 @@ private static PropertyInfo GetSingleKey<T>(string method) ...@@ -190,7 +190,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
T obj; T obj;
if (type.IsInterface()) if (type.IsInterface)
{ {
var res = connection.Query(sql, dynParms).FirstOrDefault() as IDictionary<string, object>; var res = connection.Query(sql, dynParms).FirstOrDefault() as IDictionary<string, object>;
...@@ -203,7 +203,7 @@ private static PropertyInfo GetSingleKey<T>(string method) ...@@ -203,7 +203,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
{ {
var val = res[property.Name]; var val = res[property.Name];
if (val == null) continue; if (val == null) continue;
if (property.PropertyType.IsGenericType() && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{ {
var genericType = Nullable.GetUnderlyingType(property.PropertyType); var genericType = Nullable.GetUnderlyingType(property.PropertyType);
if (genericType != null) property.SetValue(obj, Convert.ChangeType(val, genericType), null); if (genericType != null) property.SetValue(obj, Convert.ChangeType(val, genericType), null);
...@@ -248,7 +248,7 @@ private static PropertyInfo GetSingleKey<T>(string method) ...@@ -248,7 +248,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
GetQueries[cacheType.TypeHandle] = sql; GetQueries[cacheType.TypeHandle] = sql;
} }
if (!type.IsInterface()) return connection.Query<T>(sql, null, transaction, commandTimeout: commandTimeout); if (!type.IsInterface) return connection.Query<T>(sql, null, transaction, commandTimeout: commandTimeout);
var result = connection.Query(sql); var result = connection.Query(sql);
var list = new List<T>(); var list = new List<T>();
...@@ -259,7 +259,7 @@ private static PropertyInfo GetSingleKey<T>(string method) ...@@ -259,7 +259,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
{ {
var val = res[property.Name]; var val = res[property.Name];
if (val == null) continue; if (val == null) continue;
if (property.PropertyType.IsGenericType() && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{ {
var genericType = Nullable.GetUnderlyingType(property.PropertyType); var genericType = Nullable.GetUnderlyingType(property.PropertyType);
if (genericType != null) property.SetValue(obj, Convert.ChangeType(val, genericType), null); if (genericType != null) property.SetValue(obj, Convert.ChangeType(val, genericType), null);
...@@ -307,7 +307,7 @@ private static string GetTableName(Type type) ...@@ -307,7 +307,7 @@ private static string GetTableName(Type type)
else else
{ {
name = type.Name + "s"; name = type.Name + "s";
if (type.IsInterface() && name.StartsWith("I")) if (type.IsInterface && name.StartsWith("I"))
name = name.Substring(1); name = name.Substring(1);
} }
} }
...@@ -336,11 +336,11 @@ private static string GetTableName(Type type) ...@@ -336,11 +336,11 @@ private static string GetTableName(Type type)
isList = true; isList = true;
type = type.GetElementType(); type = type.GetElementType();
} }
else if (type.IsGenericType()) else if (type.IsGenericType)
{ {
var typeInfo = type.GetTypeInfo(); var typeInfo = type.GetTypeInfo();
bool implementsGenericIEnumerableOrIsGenericIEnumerable = bool implementsGenericIEnumerableOrIsGenericIEnumerable =
typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType() && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) || typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) ||
typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>); typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>);
if (implementsGenericIEnumerableOrIsGenericIEnumerable) if (implementsGenericIEnumerableOrIsGenericIEnumerable)
...@@ -417,11 +417,11 @@ private static string GetTableName(Type type) ...@@ -417,11 +417,11 @@ private static string GetTableName(Type type)
{ {
type = type.GetElementType(); type = type.GetElementType();
} }
else if (type.IsGenericType()) else if (type.IsGenericType)
{ {
var typeInfo = type.GetTypeInfo(); var typeInfo = type.GetTypeInfo();
bool implementsGenericIEnumerableOrIsGenericIEnumerable = bool implementsGenericIEnumerableOrIsGenericIEnumerable =
typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType() && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) || typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) ||
typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>); typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>);
if (implementsGenericIEnumerableOrIsGenericIEnumerable) if (implementsGenericIEnumerableOrIsGenericIEnumerable)
...@@ -486,11 +486,11 @@ private static string GetTableName(Type type) ...@@ -486,11 +486,11 @@ private static string GetTableName(Type type)
{ {
type = type.GetElementType(); type = type.GetElementType();
} }
else if (type.IsGenericType()) else if (type.IsGenericType)
{ {
var typeInfo = type.GetTypeInfo(); var typeInfo = type.GetTypeInfo();
bool implementsGenericIEnumerableOrIsGenericIEnumerable = bool implementsGenericIEnumerableOrIsGenericIEnumerable =
typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType() && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) || typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) ||
typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>); typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>);
if (implementsGenericIEnumerableOrIsGenericIEnumerable) if (implementsGenericIEnumerableOrIsGenericIEnumerable)
......
...@@ -252,7 +252,7 @@ protected Action<TDatabase> CreateTableConstructor(params Type[] tableTypes) ...@@ -252,7 +252,7 @@ protected Action<TDatabase> CreateTableConstructor(params Type[] tableTypes)
var il = dm.GetILGenerator(); var il = dm.GetILGenerator();
var setters = GetType().GetProperties() var setters = GetType().GetProperties()
.Where(p => p.PropertyType.IsGenericType() && tableTypes.Contains(p.PropertyType.GetGenericTypeDefinition())) .Where(p => p.PropertyType.IsGenericType && tableTypes.Contains(p.PropertyType.GetGenericTypeDefinition()))
.Select(p => Tuple.Create( .Select(p => Tuple.Create(
p.GetSetMethod(true), p.GetSetMethod(true),
p.PropertyType.GetConstructor(new[] { typeof(TDatabase), typeof(string) }), p.PropertyType.GetConstructor(new[] { typeof(TDatabase), typeof(string) }),
......
...@@ -91,8 +91,8 @@ private static List<PropertyInfo> RelevantProperties() ...@@ -91,8 +91,8 @@ private static List<PropertyInfo> RelevantProperties()
p.GetSetMethod(true) != null p.GetSetMethod(true) != null
&& p.GetGetMethod(true) != null && p.GetGetMethod(true) != null
&& (p.PropertyType == typeof(string) && (p.PropertyType == typeof(string)
|| p.PropertyType.IsValueType() || p.PropertyType.IsValueType
|| (p.PropertyType.IsGenericType() && p.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))) || (p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)))
).ToList(); ).ToList();
} }
......
...@@ -26,4 +26,5 @@ ...@@ -26,4 +26,5 @@
</PackageReference> </PackageReference>
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" /> <PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
</ItemGroup> </ItemGroup>
<!-- note: define SQLCE if SQL CE is available -->
</Project> </Project>
...@@ -2,14 +2,10 @@ ...@@ -2,14 +2,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using System.Transactions;
using Dapper.Contrib.Extensions; using Dapper.Contrib.Extensions;
using Xunit; using Xunit;
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using System.Transactions;
using System.Data.SqlServerCe;
#endif
using FactAttribute = Dapper.Tests.Contrib.SkippableFactAttribute; using FactAttribute = Dapper.Tests.Contrib.SkippableFactAttribute;
namespace Dapper.Tests.Contrib namespace Dapper.Tests.Contrib
...@@ -525,7 +521,7 @@ public void InsertGetUpdate() ...@@ -525,7 +521,7 @@ public void InsertGetUpdate()
} }
} }
#if !NETCOREAPP1_0 && !NETCOREAPP2_0 #if SQLCE
[Fact(Skip = "Not parallel friendly - thinking about how to test this")] [Fact(Skip = "Not parallel friendly - thinking about how to test this")]
public void InsertWithCustomDbType() public void InsertWithCustomDbType()
{ {
...@@ -563,7 +559,7 @@ public void InsertWithCustomTableNameMapper() ...@@ -563,7 +559,7 @@ public void InsertWithCustomTableNameMapper()
{ {
SqlMapperExtensions.TableNameMapper = type => SqlMapperExtensions.TableNameMapper = type =>
{ {
switch (type.Name()) switch (type.Name)
{ {
case "Person": case "Person":
return "People"; return "People";
...@@ -573,7 +569,7 @@ public void InsertWithCustomTableNameMapper() ...@@ -573,7 +569,7 @@ public void InsertWithCustomTableNameMapper()
return tableattr.Name; return tableattr.Name;
var name = type.Name + "s"; var name = type.Name + "s";
if (type.IsInterface() && name.StartsWith("I")) if (type.IsInterface && name.StartsWith("I"))
return name.Substring(1); return name.Substring(1);
return name; return name;
} }
...@@ -653,7 +649,6 @@ public void Transactions() ...@@ -653,7 +649,6 @@ public void Transactions()
} }
} }
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
[Fact] [Fact]
public void TransactionScope() public void TransactionScope()
{ {
...@@ -665,11 +660,10 @@ public void TransactionScope() ...@@ -665,11 +660,10 @@ public void TransactionScope()
txscope.Dispose(); //rollback txscope.Dispose(); //rollback
Assert.IsNull(connection.Get<Car>(id)); //returns null - car with that id should not exist Assert.Null(connection.Get<Car>(id)); //returns null - car with that id should not exist
} }
} }
} }
#endif
[Fact] [Fact]
public void InsertCheckKey() public void InsertCheckKey()
......
...@@ -7,10 +7,6 @@ ...@@ -7,10 +7,6 @@
using Xunit; using Xunit;
using Xunit.Sdk; using Xunit.Sdk;
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using System.Data.SqlServerCe;
#endif
namespace Dapper.Tests.Contrib namespace Dapper.Tests.Contrib
{ {
// The test suites here implement TestSuiteBase so that each provider runs // The test suites here implement TestSuiteBase so that each provider runs
...@@ -148,7 +144,8 @@ static SQLiteTestSuite() ...@@ -148,7 +144,8 @@ static SQLiteTestSuite()
} }
} }
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
#if SQLCE
public class SqlCETestSuite : TestSuite public class SqlCETestSuite : TestSuite
{ {
const string FileName = "Test.DB.sdf"; const string FileName = "Test.DB.sdf";
......
using System; using System;
using System.Data; using System.Data;
#if !NETSTANDARD1_3
namespace Dapper namespace Dapper
{ {
internal sealed class DataTableHandler : SqlMapper.ITypeHandler internal sealed class DataTableHandler : SqlMapper.ITypeHandler
...@@ -16,4 +15,3 @@ public void SetValue(IDbDataParameter parameter, object value) ...@@ -16,4 +15,3 @@ public void SetValue(IDbDataParameter parameter, object value)
} }
} }
} }
#endif
\ No newline at end of file
...@@ -26,27 +26,11 @@ public DefaultTypeMap(Type type) ...@@ -26,27 +26,11 @@ public DefaultTypeMap(Type type)
Properties = GetSettableProps(type); Properties = GetSettableProps(type);
_type = type; _type = type;
} }
#if NETSTANDARD1_3
private static bool IsParameterMatch(ParameterInfo[] x, ParameterInfo[] y)
{
if (ReferenceEquals(x, y)) return true;
if (x == null || y == null) return false;
if (x.Length != y.Length) return false;
for (int i = 0; i < x.Length; i++)
if (x[i].ParameterType != y[i].ParameterType) return false;
return true;
}
#endif
internal static MethodInfo GetPropertySetter(PropertyInfo propertyInfo, Type type) internal static MethodInfo GetPropertySetter(PropertyInfo propertyInfo, Type type)
{ {
if (propertyInfo.DeclaringType == type) return propertyInfo.GetSetMethod(true); if (propertyInfo.DeclaringType == type) return propertyInfo.GetSetMethod(true);
#if NETSTANDARD1_3
return propertyInfo.DeclaringType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Single(x => x.Name == propertyInfo.Name
&& x.PropertyType == propertyInfo.PropertyType
&& IsParameterMatch(x.GetIndexParameters(), propertyInfo.GetIndexParameters())
).GetSetMethod(true);
#else
return propertyInfo.DeclaringType.GetProperty( return propertyInfo.DeclaringType.GetProperty(
propertyInfo.Name, propertyInfo.Name,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
...@@ -54,7 +38,6 @@ internal static MethodInfo GetPropertySetter(PropertyInfo propertyInfo, Type typ ...@@ -54,7 +38,6 @@ internal static MethodInfo GetPropertySetter(PropertyInfo propertyInfo, Type typ
propertyInfo.PropertyType, propertyInfo.PropertyType,
propertyInfo.GetIndexParameters().Select(p => p.ParameterType).ToArray(), propertyInfo.GetIndexParameters().Select(p => p.ParameterType).ToArray(),
null).GetSetMethod(true); null).GetSetMethod(true);
#endif
} }
internal static List<PropertyInfo> GetSettableProps(Type t) internal static List<PropertyInfo> GetSettableProps(Type t)
...@@ -97,9 +80,9 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types) ...@@ -97,9 +80,9 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
continue; continue;
var unboxedType = Nullable.GetUnderlyingType(ctorParameters[i].ParameterType) ?? ctorParameters[i].ParameterType; var unboxedType = Nullable.GetUnderlyingType(ctorParameters[i].ParameterType) ?? ctorParameters[i].ParameterType;
if ((unboxedType != types[i] && !SqlMapper.HasTypeHandler(unboxedType)) if ((unboxedType != types[i] && !SqlMapper.HasTypeHandler(unboxedType))
&& !(unboxedType.IsEnum() && Enum.GetUnderlyingType(unboxedType) == types[i]) && !(unboxedType.IsEnum && Enum.GetUnderlyingType(unboxedType) == types[i])
&& !(unboxedType == typeof(char) && types[i] == typeof(string)) && !(unboxedType == typeof(char) && types[i] == typeof(string))
&& !(unboxedType.IsEnum() && types[i] == typeof(string))) && !(unboxedType.IsEnum && types[i] == typeof(string)))
{ {
break; break;
} }
...@@ -118,11 +101,7 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types) ...@@ -118,11 +101,7 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
public ConstructorInfo FindExplicitConstructor() public ConstructorInfo FindExplicitConstructor()
{ {
var constructors = _type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var constructors = _type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
#if NETSTANDARD1_3
var withAttr = constructors.Where(c => c.CustomAttributes.Any(x => x.AttributeType == typeof(ExplicitConstructorAttribute))).ToList();
#else
var withAttr = constructors.Where(c => c.GetCustomAttributes(typeof(ExplicitConstructorAttribute), true).Length > 0).ToList(); var withAttr = constructors.Where(c => c.GetCustomAttributes(typeof(ExplicitConstructorAttribute), true).Length > 0).ToList();
#endif
if (withAttr.Count == 1) if (withAttr.Count == 1)
{ {
......
...@@ -6,10 +6,6 @@ ...@@ -6,10 +6,6 @@
using System.Reflection; using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
#if NETSTANDARD1_3
using ApplicationException = System.InvalidOperationException;
#endif
namespace Dapper namespace Dapper
{ {
/// <summary> /// <summary>
......
...@@ -5,9 +5,7 @@ ...@@ -5,9 +5,7 @@
namespace Dapper namespace Dapper
{ {
internal sealed class SqlDataRecordHandler<T> : SqlMapper.ITypeHandler internal sealed class SqlDataRecordHandler<T> : SqlMapper.ITypeHandler
#if !NETSTANDARD1_3
where T : IDataRecord where T : IDataRecord
#endif
{ {
public object Parse(Type destinationType, object value) public object Parse(Type destinationType, object value)
{ {
......
...@@ -12,9 +12,7 @@ namespace Dapper ...@@ -12,9 +12,7 @@ namespace Dapper
/// Used to pass a IEnumerable&lt;SqlDataRecord&gt; as a SqlDataRecordListTVPParameter /// Used to pass a IEnumerable&lt;SqlDataRecord&gt; as a SqlDataRecordListTVPParameter
/// </summary> /// </summary>
internal sealed class SqlDataRecordListTVPParameter<T> : SqlMapper.ICustomQueryParameter internal sealed class SqlDataRecordListTVPParameter<T> : SqlMapper.ICustomQueryParameter
#if !NETSTANDARD1_3
where T : IDataRecord where T : IDataRecord
#endif
{ {
private readonly IEnumerable<T> data; private readonly IEnumerable<T> data;
private readonly string typeName; private readonly string typeName;
......
#if !NETSTANDARD1_3 // needs the component-model API using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
...@@ -104,4 +103,3 @@ public override void SetValue(object component, object value) ...@@ -104,4 +103,3 @@ public override void SetValue(object component, object value)
} }
} }
} }
#endif
...@@ -140,7 +140,7 @@ public static IEnumerable<dynamic> Parse(this IDataReader reader) ...@@ -140,7 +140,7 @@ public static IEnumerable<dynamic> Parse(this IDataReader reader)
{ {
concreteType = concreteType ?? typeof(T); concreteType = concreteType ?? typeof(T);
var func = GetDeserializer(concreteType, reader, startIndex, length, returnNullIfFirstMissing); var func = GetDeserializer(concreteType, reader, startIndex, length, returnNullIfFirstMissing);
if (concreteType.IsValueType()) if (concreteType.IsValueType)
{ {
return _ => (T)func(_); return _ => (T)func(_);
} }
......
...@@ -11,9 +11,7 @@ public static partial class SqlMapper ...@@ -11,9 +11,7 @@ public static partial class SqlMapper
/// </summary> /// </summary>
/// <typeparam name="T">The type to have a cache for.</typeparam> /// <typeparam name="T">The type to have a cache for.</typeparam>
[Obsolete(ObsoleteInternalUsageOnly, false)] [Obsolete(ObsoleteInternalUsageOnly, false)]
#if !NETSTANDARD1_3
[Browsable(false)] [Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never)] [EditorBrowsable(EditorBrowsableState.Never)]
public static class TypeHandlerCache<T> public static class TypeHandlerCache<T>
{ {
......
This diff is collapsed.
using System.Data; using System.Data;
#if !NETSTANDARD1_3
namespace Dapper namespace Dapper
{ {
/// <summary> /// <summary>
...@@ -49,4 +48,3 @@ internal static void Set(IDbDataParameter parameter, DataTable table, string typ ...@@ -49,4 +48,3 @@ internal static void Set(IDbDataParameter parameter, DataTable table, string typ
} }
} }
} }
#endif
using System; using System;
using System.Reflection; using System.Reflection;
using System.Collections.Generic;
namespace Dapper namespace Dapper
{ {
internal static class TypeExtensions internal static class TypeExtensions
{ {
public static string Name(this Type type) =>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().Name;
#else
type.Name;
#endif
public static bool IsValueType(this Type type) =>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().IsValueType;
#else
type.IsValueType;
#endif
public static bool IsEnum(this Type type) =>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().IsEnum;
#else
type.IsEnum;
#endif
public static bool IsGenericType(this Type type) =>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().IsGenericType;
#else
type.IsGenericType;
#endif
public static bool IsInterface(this Type type) =>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().IsInterface;
#else
type.IsInterface;
#endif
#if NETSTANDARD1_3 || NETCOREAPP1_0
public static IEnumerable<Attribute> GetCustomAttributes(this Type type, bool inherit)
{
return type.GetTypeInfo().GetCustomAttributes(inherit);
}
public static TypeCode GetTypeCode(Type type)
{
if (type == null) return TypeCode.Empty;
if (typeCodeLookup.TryGetValue(type, out TypeCode result)) return result;
if (type.IsEnum())
{
type = Enum.GetUnderlyingType(type);
if (typeCodeLookup.TryGetValue(type, out result)) return result;
}
return TypeCode.Object;
}
private static readonly Dictionary<Type, TypeCode> typeCodeLookup = new Dictionary<Type, TypeCode>
{
[typeof(bool)] = TypeCode.Boolean,
[typeof(byte)] = TypeCode.Byte,
[typeof(char)] = TypeCode.Char,
[typeof(DateTime)] = TypeCode.DateTime,
[typeof(decimal)] = TypeCode.Decimal,
[typeof(double)] = TypeCode.Double,
[typeof(short)] = TypeCode.Int16,
[typeof(int)] = TypeCode.Int32,
[typeof(long)] = TypeCode.Int64,
[typeof(object)] = TypeCode.Object,
[typeof(sbyte)] = TypeCode.SByte,
[typeof(float)] = TypeCode.Single,
[typeof(string)] = TypeCode.String,
[typeof(ushort)] = TypeCode.UInt16,
[typeof(uint)] = TypeCode.UInt32,
[typeof(ulong)] = TypeCode.UInt64,
};
#else
public static TypeCode GetTypeCode(Type type) => Type.GetTypeCode(type);
#endif
public static MethodInfo GetPublicInstanceMethod(this Type type, string name, Type[] types) public static MethodInfo GetPublicInstanceMethod(this Type type, string name, Type[] types)
{ => type.GetMethod(name, BindingFlags.Instance | BindingFlags.Public, null, types, null);
#if NETSTANDARD1_3 || NETCOREAPP1_0
var method = type.GetMethod(name, types);
return (method?.IsPublic == true && !method.IsStatic) ? method : null;
#else
return type.GetMethod(name, BindingFlags.Instance | BindingFlags.Public, null, types, null);
#endif
}
} }
} }
...@@ -5,7 +5,6 @@ namespace Dapper ...@@ -5,7 +5,6 @@ namespace Dapper
{ {
public static partial class SqlMapper public static partial class SqlMapper
{ {
#if !NETSTANDARD1_3 && !NETSTANDARD2_0
/// <summary> /// <summary>
/// A type handler for data-types that are supported by the underlying provider, but which need /// A type handler for data-types that are supported by the underlying provider, but which need
/// a well-known UdtTypeName to be specified /// a well-known UdtTypeName to be specified
...@@ -36,6 +35,5 @@ void ITypeHandler.SetValue(IDbDataParameter parameter, object value) ...@@ -36,6 +35,5 @@ void ITypeHandler.SetValue(IDbDataParameter parameter, object value)
if(!(value is DBNull)) StructuredHelper.ConfigureUDT(parameter, udtTypeName); if(!(value is DBNull)) StructuredHelper.ConfigureUDT(parameter, udtTypeName);
} }
} }
#endif
} }
} }
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