Commit 7e5bd308 authored by Nick Craver's avatar Nick Craver

netstandard2.0 functionality (w/ runtime breaks)

This adds a netstandard2.0 build to Dapper (and StrongName until v2),
adds a netstandard2.0 test lineup, restores most functionality (except
UDTs for SQL, e.g. .UdtTypeName isn't in netstandard2), and also breaks
things not actually implemented or implemented correctly in
netstandard2.0. Pushing this up so we can work through these with the
.NET teams.

Several things are still broken here (and fail tests):
- Parameter decimal values (not filed yet)
- DataTables as parameters
(https://github.com/dotnet/corefx/issues/19708)
- .GetSchemaTable() (not yet filed, implementation is completely missing
from SqlDataReader in CoreFX)

While the compile is clean, the above are runtime issues.
`SqlParameter.UdtTypeName` is a separate issue, that one just wasn't in
`netstandard2.0` at all...so we can't support UDTs there until it is.
See https://github.com/dotnet/corefx/issues/17126 for details.
parent d72ae17a
......@@ -9,7 +9,7 @@
using Dapper;
#if COREFX
#if NETSTANDARD1_3
using DataException = System.InvalidOperationException;
#else
using System.Threading;
......@@ -274,7 +274,7 @@ private static string GetTableName(Type type)
{
//NOTE: This as dynamic trick should be able to handle both our own Table-attribute as well as the one in EntityFramework
var tableAttr = type
#if COREFX
#if NETSTANDARD1_3
.GetTypeInfo()
#endif
.GetCustomAttributes(false).SingleOrDefault(attr => attr.GetType().Name == "TableAttribute") as dynamic;
......@@ -516,7 +516,7 @@ private static class ProxyGenerator
private static AssemblyBuilder GetAsmBuilder(string name)
{
#if COREFX
#if NETSTANDARD1_3
return AssemblyBuilder.DefineDynamicAssembly(new AssemblyName { Name = name }, AssemblyBuilderAccess.Run);
#else
return Thread.GetDomain().DefineDynamicAssembly(new AssemblyName { Name = name }, AssemblyBuilderAccess.Run);
......@@ -551,7 +551,7 @@ public static T GetInterfaceProxy<T>()
CreateProperty<T>(typeBuilder, property.Name, property.PropertyType, setIsDirtyMethod, isId);
}
#if COREFX
#if NETSTANDARD1_3
var generatedType = typeBuilder.CreateTypeInfo().AsType();
#else
var generatedType = typeBuilder.CreateType();
......
......@@ -5,7 +5,7 @@
<Title>Dapper (Strong Named)</Title>
<Description>A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..</Description>
<Authors>Sam Saffron;Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net40;net45;net451;netstandard1.3</TargetFrameworks>
<TargetFrameworks>net40;net45;net451;netstandard1.3;netstandard2.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
</PropertyGroup>
......@@ -30,4 +30,9 @@
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview1-25305-02" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
</ItemGroup>
</Project>
......@@ -6,10 +6,7 @@
<DebugType>portable</DebugType>
<OutputType>Exe</OutputType>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);COREFX;</DefineConstants>
<TargetFrameworks>netcoreapp1.0;netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Dapper.Tests\Helpers\Assert.cs;..\Dapper.Tests\Helpers\XunitSkippable.cs;..\Dapper\TypeExtensions.cs" />
......@@ -19,15 +16,14 @@
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<ProjectReference Include="..\Dapper.SqlBuilder\Dapper.SqlBuilder.csproj" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.3.0" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview1-25305-02" />
<PackageReference Include="xunit" Version="2.3.0-beta1-build3642" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta1-build3642" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
......
......@@ -5,10 +5,12 @@
using Dapper.Contrib.Extensions;
#if !COREFX
using System.Data.SqlServerCe;
#if !NETCOREAPP1_0
using System.Transactions;
#endif
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using System.Data.SqlServerCe;
#endif
using FactAttribute = Dapper.Tests.Contrib.SkippableFactAttribute;
namespace Dapper.Tests.Contrib
......@@ -420,7 +422,7 @@ public void InsertGetUpdate()
}
}
#if !COREFX
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
[Fact(Skip = "Not parallel friendly - thinking about how to test this")]
public void InsertWithCustomDbType()
{
......@@ -525,7 +527,7 @@ public void Transactions()
}
}
#if !COREFX
#if !NETCOREAPP1_0
[Fact]
public void TransactionScope()
{
......@@ -632,4 +634,3 @@ public void DeleteAll()
}
}
}
using System;
using Microsoft.Data.Sqlite;
using MySql.Data.MySqlClient;
using System;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using Xunit;
using Xunit.Sdk;
#if COREFX
using Microsoft.Data.Sqlite;
#else
using System.Data.SQLite;
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using System.Data.SqlServerCe;
using MySql.Data.MySqlClient;
using SqliteConnection = System.Data.SQLite.SQLiteConnection;
#endif
namespace Dapper.Tests.Contrib
......@@ -60,7 +58,6 @@ static SqlServerTestSuite()
}
}
#if !COREFX
public class MySqlServerTestSuite : TestSuite
{
const string DbName = "DapperContribTests";
......@@ -115,14 +112,11 @@ static MySqlServerTestSuite()
}
}
}
// This doesn't work on COREFX right now due to:
// In Visual Studio: Interop loads (works from console, though)
// In general: parameter names, see https://github.com/StackExchange/dapper-dot-net/issues/375
public class SQLiteTestSuite : TestSuite
{
const string FileName = "Test.DB.sqlite";
public static string ConnectionString => $"Filename={FileName};";
public static string ConnectionString => $"Filename=./{FileName};Mode=ReadWriteCreate;";
public override IDbConnection GetConnection() => new SqliteConnection(ConnectionString);
static SQLiteTestSuite()
......@@ -131,7 +125,6 @@ static SQLiteTestSuite()
{
File.Delete(FileName);
}
SqliteConnection.CreateFile(FileName);
using (var connection = new SqliteConnection(ConnectionString))
{
connection.Open();
......@@ -147,6 +140,7 @@ static SQLiteTestSuite()
}
}
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
public class SqlCETestSuite : TestSuite
{
const string FileName = "Test.DB.sdf";
......
......@@ -9,7 +9,7 @@ public class HandCodedBenchmarks : BenchmarkBase
{
private SqlCommand _postCommand;
private SqlParameter _idParam;
#if !COREFX
#if !NETCOREAPP1_0
private DataTable _table;
#endif
......@@ -24,7 +24,7 @@ public void Setup()
Counter1,Counter2,Counter3,Counter4,Counter5,Counter6,Counter7,Counter8,Counter9 from Posts where Id = @Id"
};
_idParam = _postCommand.Parameters.Add("@Id", SqlDbType.Int);
#if !COREFX
#if !NETCOREAPP1_0
_table = new DataTable
{
Columns =
......
......@@ -332,7 +332,7 @@ public async Task RunAsync(int iterations)
}
}, "Hand Coded");
#if !COREFX
#if !NETSTANDARD1_3
var table = new DataTable
{
Columns =
......
#if !COREFX
#if !NETSTANDARD1_3
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
......
#if !COREFX
#if !NETSTANDARD1_3
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
......
#if !COREFX
#if !NETSTANDARD1_3
using System;
using System.Collections.Generic;
using System.Linq;
......
......@@ -218,7 +218,7 @@ public async Task TestMultiClosedConnAsyncViaFirstOrDefault()
}
}
#if !COREFX
#if !NETCOREAPP1_0
[Fact]
public async Task ExecuteReaderOpenAsync()
{
......@@ -318,8 +318,8 @@ public async Task LiteralInAsync()
new { ids = new[] { 1, 3, 4 } }).ConfigureAwait(false)).Single();
count.IsEqualTo(2);
}
[Fact]
[FactLongRunning]
public async Task RunSequentialVersusParallelAsync()
{
var ids = Enumerable.Range(1, 20000).Select(id => new { id }).ToArray();
......@@ -336,7 +336,7 @@ public async Task RunSequentialVersusParallelAsync()
Console.WriteLine("Pipeline: {0}ms", watch.ElapsedMilliseconds);
}
[Fact]
[FactLongRunning]
public void RunSequentialVersusParallelSync()
{
var ids = Enumerable.Range(1, 20000).Select(id => new { id }).ToArray();
......
......@@ -104,28 +104,6 @@ public bool GetWentThroughProperConstructor()
}
}
#if LINQ2SQL
private class NoDefaultConstructorWithBinary
{
public System.Data.Linq.Binary Value { get; set; }
public int Ynt { get; set; }
public NoDefaultConstructorWithBinary(System.Data.Linq.Binary val)
{
Value = val;
}
}
[Fact]
public void TestNoDefaultConstructorBinary()
{
byte[] orig = new byte[20];
new Random(123456).NextBytes(orig);
var input = new System.Data.Linq.Binary(orig);
var output = connection.Query<NoDefaultConstructorWithBinary>("select @input as val", new { input }).First().Value;
output.ToArray().IsSequenceEqualTo(orig);
}
#endif
[Fact]
public void Issue461_TypeHandlerWorksInConstructor()
{
......
......@@ -6,14 +6,11 @@
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<TargetFrameworks>net452;netcoreapp1.0</TargetFrameworks>
<TargetFrameworks>net452;netcoreapp1.0;netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net452' ">
<DefineConstants>$(DefineConstants);NET45;MYSQL;ENTITY_FRAMEWORK;LINQ2SQL;FIREBIRD;SQL_CE;POSTGRESQL;OLEDB;SQLITE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);COREFX</DefineConstants>
<DefineConstants>$(DefineConstants);ENTITY_FRAMEWORK;LINQ2SQL;SQL_CE;OLEDB</DefineConstants>
</PropertyGroup>
<ItemGroup>
<None Remove="Test.DB.sdf" />
......@@ -21,23 +18,22 @@
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.9.0.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.3.0" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="Npgsql" Version="3.2.2" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview1-25305-02" />
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.3.0-beta1-build3642" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta1-build3642" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" />
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.8.0" />
<PackageReference Include="Microsoft.SqlServer.Compact" Version="4.0.8876.1" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.314.76" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="Npgsql" Version="3.2.2" />
<PackageReference Include="System.Data.SQLite" Version="1.0.104" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
......@@ -49,7 +45,6 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="System.Ben" Version="1.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
......
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace Dapper.Tests
......
......@@ -4,20 +4,6 @@
namespace Dapper.Tests
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class FactUnlessCoreCLRAttribute : FactAttribute
{
public FactUnlessCoreCLRAttribute(string url)
{
#if COREFX
Skip = $"CoreFX: {url}";
#endif
this.Url = url;
}
public string Url { get; }
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class FactLongRunningAttribute : FactAttribute
{
......
......@@ -8,7 +8,7 @@
using System.Linq;
using Xunit;
#if COREFX
#if NETCOREAPP1_0
using System.Collections;
using System.Dynamic;
using System.Data.SqlTypes;
......@@ -18,7 +18,7 @@
using System.Threading.Tasks;
#endif
#if COREFX
#if NETCOREAPP1_0
namespace System
{
public enum GenericUriParserOptions
......@@ -507,7 +507,7 @@ public void TestInheritance()
list.First().Base2.IsEqualTo("Four");
}
#if !COREFX
#if !NETCOREAPP1_0
[Fact]
public void ExecuteReader()
{
......
......@@ -10,6 +10,7 @@
using Xunit;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Diagnostics;
#if ENTITY_FRAMEWORK
using System.Data.Entity.Spatial;
......@@ -217,7 +218,7 @@ public void TestMassiveStrings()
.IsEqualTo(str);
}
#if !COREFX
#if !NETCOREAPP1_0
[Fact]
public void TestTVPWithAnonymousObject()
{
......@@ -491,7 +492,7 @@ public SO29596645_RuleTableValuedParameters(string parameterName)
public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
{
Console.WriteLine("> AddParameters");
Debug.WriteLine("> AddParameters");
var lazy = (SqlCommand)command;
lazy.Parameters.AddWithValue("Id", 7);
var table = new DataTable
......@@ -500,7 +501,7 @@ public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
Rows = { { 4 }, { 9 } }
};
lazy.Parameters.AddWithValue("Rules", table);
Console.WriteLine("< AddParameters");
Debug.WriteLine("< AddParameters");
}
}
......
......@@ -103,7 +103,7 @@ public void SO24605346_ProcsAndStrings()
private class PracticeRebateOrders
{
public string fTaxInvoiceNumber;
#if !COREFX
#if !NETCOREAPP1_0
[System.Xml.Serialization.XmlElement(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
#endif
public string TaxInvoiceNumber
......
#if FIREBIRD
using FirebirdSql.Data.FirebirdClient;
using FirebirdSql.Data.FirebirdClient;
using System.Data;
using System.Linq;
using Xunit;
......@@ -45,5 +44,4 @@ public void Issue178_Firebird()
}
}
}
}
#endif
\ No newline at end of file
}
\ No newline at end of file
......@@ -38,6 +38,27 @@ private class WithBinary
{
public System.Data.Linq.Binary Value { get; set; }
}
private class NoDefaultConstructorWithBinary
{
public System.Data.Linq.Binary Value { get; set; }
public int Ynt { get; set; }
public NoDefaultConstructorWithBinary(System.Data.Linq.Binary val)
{
Value = val;
}
}
[Fact]
public void TestNoDefaultConstructorBinary()
{
byte[] orig = new byte[20];
new Random(123456).NextBytes(orig);
var input = new System.Data.Linq.Binary(orig);
var output = connection.Query<NoDefaultConstructorWithBinary>("select @input as val", new { input }).First().Value;
output.ToArray().IsSequenceEqualTo(orig);
}
}
}
#endif
\ No newline at end of file
#if MYSQL
using System;
using System;
using System.Linq;
using Xunit;
......@@ -185,5 +184,4 @@ static FactMySqlAttribute()
}
}
}
}
#endif
\ No newline at end of file
}
\ No newline at end of file
#if POSTGRESQL
using System;
using System;
using System.Data;
using System.Linq;
using Xunit;
......@@ -80,5 +79,4 @@ static FactPostgresqlAttribute()
}
}
}
}
#endif
\ No newline at end of file
}
\ No newline at end of file
#if SQLITE
using Microsoft.Data.Sqlite;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Data.SQLite;
using System.Data;
using Xunit;
namespace Dapper.Tests
{
public class SqliteTests : TestBase
{
protected static SQLiteConnection GetSQLiteConnection(bool open = true)
protected static SqliteConnection GetSQLiteConnection(bool open = true)
{
var connection = new SQLiteConnection("Data Source=:memory:");
var connection = new SqliteConnection("Data Source=:memory:");
if (open) connection.Open();
return connection;
}
......@@ -82,11 +80,7 @@ private void Isse467_SqliteParameterNaming(bool prefix)
{
var cmd = connection.CreateCommand();
cmd.CommandText = "select @foo";
#if NET45
const DbType type = DbType.Int32;
#else
const SqliteType type = SqliteType.Integer;
#endif
cmd.Parameters.Add(prefix ? "@foo" : "foo", type).Value = 42;
var i = Convert.ToInt32(cmd.ExecuteScalar());
i.IsEqualTo(42);
......@@ -118,5 +112,4 @@ static FactSqliteAttribute()
}
}
}
}
#endif
\ No newline at end of file
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
#if !COREFX
#if !NETCOREAPP1_0
using System.Threading;
#endif
......@@ -45,7 +45,7 @@ public SqlConnection GetClosedConnection()
protected static CultureInfo ActiveCulture
{
#if COREFX
#if NETCOREAPP1_0
get { return CultureInfo.CurrentCulture; }
set { CultureInfo.CurrentCulture = value; }
#else
......@@ -58,8 +58,8 @@ static TestBase()
{
Console.WriteLine("Dapper: " + typeof(SqlMapper).AssemblyQualifiedName);
Console.WriteLine("Using Connectionstring: {0}", ConnectionString);
#if COREFX
Console.WriteLine("CoreCLR");
#if NETCOREAPP1_0
Console.WriteLine("CoreCLR (netcoreapp1.0)");
#else
Console.WriteLine(".NET: " + Environment.Version);
Console.Write("Loading native assemblies for SQL types...");
......
......@@ -545,7 +545,7 @@ public void TestCustomTypeMap()
private static string GetDescriptionFromAttribute(MemberInfo member)
{
if (member == null) return null;
#if COREFX
#if NETCOREAPP1_0
var data = member.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(DescriptionAttribute));
return (string)data?.ConstructorArguments.Single().Value;
#else
......
......@@ -5,7 +5,7 @@
<Title>Dapper</Title>
<Description>A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..</Description>
<Authors>Sam Saffron;Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net40;net45;net451;netstandard1.3</TargetFrameworks>
<TargetFrameworks>net40;net45;net451;netstandard1.3;netstandard2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451' ">
<Reference Include="System" />
......@@ -25,4 +25,9 @@
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview1-25305-02" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
</ItemGroup>
</Project>
using System;
using System.Data;
#if !COREFX
#if !NETSTANDARD1_3
namespace Dapper
{
internal sealed class DataTableHandler : SqlMapper.ITypeHandler
......
......@@ -26,7 +26,7 @@ public DefaultTypeMap(Type type)
Properties = GetSettableProps(type);
_type = type;
}
#if COREFX
#if NETSTANDARD1_3
private static bool IsParameterMatch(ParameterInfo[] x, ParameterInfo[] y)
{
if (ReferenceEquals(x, y)) return true;
......@@ -40,7 +40,7 @@ private static bool IsParameterMatch(ParameterInfo[] x, ParameterInfo[] y)
internal static MethodInfo GetPropertySetter(PropertyInfo propertyInfo, Type type)
{
if (propertyInfo.DeclaringType == type) return propertyInfo.GetSetMethod(true);
#if COREFX
#if NETSTANDARD1_3
return propertyInfo.DeclaringType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Single(x => x.Name == propertyInfo.Name
&& x.PropertyType == propertyInfo.PropertyType
......@@ -118,7 +118,7 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
public ConstructorInfo FindExplicitConstructor()
{
var constructors = _type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
#if COREFX
#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();
......
......@@ -6,7 +6,7 @@
using System.Reflection;
using System.Reflection.Emit;
#if COREFX
#if NETSTANDARD1_3
using ApplicationException = System.InvalidOperationException;
#endif
......
......@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Data;
#if !COREFX
#if !NETSTANDARD1_3
namespace Dapper
{
internal sealed class SqlDataRecordHandler : SqlMapper.ITypeHandler
......
......@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Data;
using System.Reflection;
#if !COREFX
#if !NETSTANDARD1_3
namespace Dapper
{
/// <summary>
......
......@@ -11,7 +11,7 @@ public static partial class SqlMapper
/// </summary>
/// <typeparam name="T">The type to have a cache for.</typeparam>
[Obsolete(ObsoleteInternalUsageOnly, false)]
#if !COREFX
#if !NETSTANDARD1_3
[Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never)]
......
......@@ -19,7 +19,7 @@
using System.Xml;
using System.Xml.Linq;
#if COREFX
#if NETSTANDARD1_3
using DataException = System.InvalidOperationException;
#endif
......@@ -217,7 +217,7 @@ static SqlMapper()
private static void ResetTypeHandlers(bool clone)
{
typeHandlers = new Dictionary<Type, ITypeHandler>();
#if !COREFX
#if !NETSTANDARD1_3
AddTypeHandlerImpl(typeof(DataTable), new DataTableHandler(), clone);
try
{
......@@ -230,7 +230,7 @@ private static void ResetTypeHandlers(bool clone)
AddTypeHandlerImpl(typeof(XElement), new XElementHandler(), clone);
}
#if !COREFX
#if !NETSTANDARD1_3
[MethodImpl(MethodImplOptions.NoInlining)]
private static void AddSqlDataRecordsTypeHandler(bool clone)
{
......@@ -348,7 +348,7 @@ public static void AddTypeHandlerImpl(Type type, ITypeHandler handler, bool clon
/// </summary>
/// <param name="value">The object to get a corresponding database type for.</param>
[Obsolete(ObsoleteInternalUsageOnly, false)]
#if !COREFX
#if !NETSTANDARD1_3
[Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never)]
......@@ -367,7 +367,7 @@ public static DbType GetDbType(object value)
/// <param name="demand">Whether to demand a value (throw if missing).</param>
/// <param name="handler">The handler for <paramref name="type"/>.</param>
[Obsolete(ObsoleteInternalUsageOnly, false)]
#if !COREFX
#if !NETSTANDARD1_3
[Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never)]
......@@ -397,7 +397,7 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
return DynamicParameters.EnumerableMultiParameter;
}
#if !COREFX
#if !NETSTANDARD1_3 && !NETSTANDARD2_0
switch (type.FullName)
{
case "Microsoft.SqlServer.Types.SqlGeography":
......@@ -1864,7 +1864,7 @@ private static Exception MultiMapException(IDataRecord reader)
/// Internal use only.
/// </summary>
/// <param name="value">The object to convert to a character.</param>
#if !COREFX
#if !NETSTANDARD1_3
[Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never)]
......@@ -1881,7 +1881,7 @@ public static char ReadChar(object value)
/// Internal use only.
/// </summary>
/// <param name="value">The object to convert to a character.</param>
#if !COREFX
#if !NETSTANDARD1_3
[Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never)]
......@@ -1900,7 +1900,7 @@ public static char ReadChar(object value)
/// <param name="parameters">The parameter collection to search in.</param>
/// <param name="command">The command for this fetch.</param>
/// <param name="name">The name of the parameter to get.</param>
#if !COREFX
#if !NETSTANDARD1_3
[Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never)]
......@@ -1958,7 +1958,7 @@ internal static int GetListPaddingExtraCount(int count)
/// <param name="command">The command to pack parameters for.</param>
/// <param name="namePrefix">The name prefix for these parameters.</param>
/// <param name="value">The parameter value can be an <see cref="IEnumerable{T}"/></param>
#if !COREFX
#if !NETSTANDARD1_3
[Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never)]
......@@ -2257,7 +2257,7 @@ public static string Format(object value)
{
switch (TypeExtensions.GetTypeCode(value.GetType()))
{
#if !COREFX
#if !NETSTANDARD1_3
case TypeCode.DBNull:
return "null";
#endif
......@@ -3080,7 +3080,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
int index = startBound;
ConstructorInfo specializedConstructor = null;
#if !COREFX
#if !NETSTANDARD1_3
bool supportInitialize = false;
#endif
Dictionary<Type, LocalBuilder> structLocals = null;
......@@ -3115,7 +3115,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
il.Emit(OpCodes.Newobj, explicitConstr);
il.Emit(OpCodes.Stloc_1);
#if !COREFX
#if !NETSTANDARD1_3
supportInitialize = typeof(ISupportInitialize).IsAssignableFrom(type);
if (supportInitialize)
{
......@@ -3137,7 +3137,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
{
il.Emit(OpCodes.Newobj, ctor);
il.Emit(OpCodes.Stloc_1);
#if !COREFX
#if !NETSTANDARD1_3
supportInitialize = typeof(ISupportInitialize).IsAssignableFrom(type);
if (supportInitialize)
{
......@@ -3354,7 +3354,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
il.Emit(OpCodes.Newobj, specializedConstructor);
}
il.Emit(OpCodes.Stloc_1); // stack is empty
#if !COREFX
#if !NETSTANDARD1_3
if (supportInitialize)
{
il.Emit(OpCodes.Ldloc_1);
......@@ -3626,7 +3626,7 @@ public static IEqualityComparer<string> ConnectionStringComparer
private static IEqualityComparer<string> connectionStringComparer = StringComparer.Ordinal;
#if !COREFX
#if !NETSTANDARD1_3
/// <summary>
/// Key used to indicate the type name associated with a DataTable.
/// </summary>
......
......@@ -2,7 +2,7 @@
using System.Data;
using System.Reflection;
#if !COREFX
#if !NETSTANDARD1_3
namespace Dapper
{
/// <summary>
......
......@@ -7,41 +7,41 @@ namespace Dapper
internal static class TypeExtensions
{
public static string Name(this Type type) =>
#if COREFX
#if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().Name;
#else
type.Name;
#endif
public static bool IsValueType(this Type type) =>
#if COREFX
#if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().IsValueType;
#else
type.IsValueType;
#endif
public static bool IsEnum(this Type type) =>
#if COREFX
#if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().IsEnum;
#else
type.IsEnum;
#endif
public static bool IsGenericType(this Type type) =>
#if COREFX
#if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().IsGenericType;
#else
type.IsGenericType;
#endif
public static bool IsInterface(this Type type) =>
#if COREFX
#if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().IsInterface;
#else
type.IsInterface;
#endif
#if COREFX
#if NETSTANDARD1_3 || NETCOREAPP1_0
public static IEnumerable<Attribute> GetCustomAttributes(this Type type, bool inherit)
{
return type.GetTypeInfo().GetCustomAttributes(inherit);
......@@ -85,7 +85,7 @@ public static TypeCode GetTypeCode(Type type)
public static MethodInfo GetPublicInstanceMethod(this Type type, string name, Type[] types)
{
#if COREFX
#if NETSTANDARD1_3 || NETCOREAPP1_0
var method = type.GetMethod(name, types);
return (method?.IsPublic == true && !method.IsStatic) ? method : null;
#else
......
......@@ -5,7 +5,7 @@ namespace Dapper
{
public static partial class SqlMapper
{
#if !COREFX
#if !NETSTANDARD1_3 && !NETSTANDARD2_0
/// <summary>
/// A type handler for data-types that are supported by the underlying provider, but which need
/// a well-known UdtTypeName to be specified
......
......@@ -30,12 +30,9 @@
<Reference Include="System.Core" Pack="false" />
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451'">
<PropertyGroup Condition=" '$(TargetFramework)' != 'net40'">
<DefineConstants>$(DefineConstants);ASYNC</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<DefineConstants>$(DefineConstants);ASYNC;COREFX</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SourceLink.Create.GitHub" Version="2.0.2" PrivateAssets="All" />
......
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