Commit 9076086b authored by Nick Craver's avatar Nick Craver Committed by GitHub

Merge pull request #836 from StackExchange/netstandard2

.NET Standard 2.0, for great justice.
parents 610d8f65 9d9afeaf
......@@ -5,7 +5,7 @@
<Title>Dapper.Contrib</Title>
<Description>The official collection of get, insert, update and delete helpers for Dapper.net. Also handles lists of entities and optional "dirty" tracking of interface-based entities.</Description>
<Authors>Sam Saffron;Johan Danforth</Authors>
<TargetFrameworks>net40;net45;netstandard1.3</TargetFrameworks>
<TargetFrameworks>net451;netstandard1.3</TargetFrameworks>
<!-- TODO: Docs -->
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
......@@ -15,7 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' ">
<ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System" />
......
......@@ -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();
......
......@@ -4,7 +4,7 @@
<Title>Dapper: Entity Framework type handlers (with a strong name)</Title>
<Description>Extension handlers for entity framework</Description>
<Authors>Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net40;net45</TargetFrameworks>
<TargetFrameworks>net451</TargetFrameworks>
<AssemblyOriginatorKeyFile>../Dapper.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
......
......@@ -5,7 +5,7 @@
<AssemblyTitle>Dapper entity framework type handlers</AssemblyTitle>
<VersionPrefix>1.50.2</VersionPrefix>
<Authors>Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net40;net45</TargetFrameworks>
<TargetFrameworks>net451</TargetFrameworks>
<PackageTags>orm;sql;micro-orm</PackageTags>
</PropertyGroup>
<ItemGroup>
......
......@@ -6,7 +6,7 @@
<Description>Trivial micro-orm implemented on Dapper, provides with CRUD helpers.</Description>
<Authors>Sam Saffron</Authors>
<Copyright>2017 Sam Saffron</Copyright>
<TargetFrameworks>net40;net45;netstandard1.3</TargetFrameworks>
<TargetFrameworks>net451;netstandard1.3</TargetFrameworks>
<!-- TODO: Docs -->
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
......@@ -16,14 +16,14 @@
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' ">
<ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -5,7 +5,7 @@
<Title>Dapper SqlBuilder component</Title>
<Description>The Dapper SqlBuilder component, for building SQL queries dynamically.</Description>
<Authors>Sam Saffron, Johan Danforth</Authors>
<TargetFrameworks>net40;net45;netstandard1.3</TargetFrameworks>
<TargetFrameworks>net451;netstandard1.3</TargetFrameworks>
<!-- TODO: Docs -->
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
......@@ -13,13 +13,13 @@
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' ">
<ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -5,14 +5,14 @@
<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>net451;netstandard1.3;netstandard2.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Dapper\**\*.cs" Exclude="..\Dapper\obj\**\*.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451' ">
<ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
......@@ -22,7 +22,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
<PackageReference Include="System.Data.Common" Version="4.3.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
......@@ -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" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.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,14 +16,13 @@
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<ProjectReference Include="..\Dapper.SqlBuilder\Dapper.SqlBuilder.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="System.Data.SqlClient" 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)' == 'netcoreapp1.0' ">
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(xUnitVersion)" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
......
......@@ -5,9 +5,9 @@
using Dapper.Contrib.Extensions;
#if !COREFX
using System.Data.SqlServerCe;
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using System.Transactions;
using System.Data.SqlServerCe;
#endif
using FactAttribute = Dapper.Tests.Contrib.SkippableFactAttribute;
......@@ -420,7 +420,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 +525,7 @@ public void Transactions()
}
}
#if !COREFX
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
[Fact]
public void TransactionScope()
{
......@@ -632,4 +632,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";
......@@ -116,13 +113,10 @@ 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";
......
......@@ -8,7 +8,7 @@ public class BelgradeBenchmarks : BenchmarkBase
{
private QueryMapper _mapper;
[Setup]
[GlobalSetup]
public void Setup()
{
BaseSetup();
......
......@@ -6,7 +6,7 @@ namespace Dapper.Tests.Performance
{
public class DapperBenchmarks : BenchmarkBase
{
[Setup]
[GlobalSetup]
public void Setup()
{
BaseSetup();
......
......@@ -7,7 +7,7 @@ public class EF6Benchmarks : BenchmarkBase
{
private EntityFramework.EFContext Context;
[Setup]
[GlobalSetup]
public void Setup()
{
BaseSetup();
......
......@@ -13,7 +13,7 @@ public class EFCoreBenchmarks : BenchmarkBase
private static readonly Func<DataClassesDataContext, int, Linq2Sql.Post> compiledQuery =
CompiledQuery.Compile((DataClassesDataContext ctx, int id) => ctx.Posts.First(p => p.Id == id));
[Setup]
[GlobalSetup]
public void Setup()
{
BaseSetup();
......
......@@ -9,11 +9,11 @@ public class HandCodedBenchmarks : BenchmarkBase
{
private SqlCommand _postCommand;
private SqlParameter _idParam;
#if !COREFX
#if !NETCOREAPP1_0
private DataTable _table;
#endif
[Setup]
[GlobalSetup]
public void Setup()
{
BaseSetup();
......@@ -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 =
......
......@@ -12,7 +12,7 @@ public class Linq2SqlBenchmarks : BenchmarkBase
private static readonly Func<DataClassesDataContext, int, Linq2Sql.Post> compiledQuery =
CompiledQuery.Compile((DataClassesDataContext ctx, int id) => ctx.Posts.First(p => p.Id == id));
[Setup]
[GlobalSetup]
public void Setup()
{
BaseSetup();
......
......@@ -8,7 +8,7 @@ public class MassiveBenchmarks : BenchmarkBase
{
private DynamicModel _model;
[Setup]
[GlobalSetup]
public void Setup()
{
BaseSetup();
......
......@@ -13,7 +13,7 @@ public class NHibernateBenchmarks : BenchmarkBase
{
private IStatelessSession _sql, _hql, _criteria, _linq, _get;
[Setup]
[GlobalSetup]
public void Setup()
{
BaseSetup();
......
......@@ -8,7 +8,7 @@ public class PetaPocoBenchmarks : BenchmarkBase
{
private Database _db, _dbFast;
[Setup]
[GlobalSetup]
public void Setup()
{
BaseSetup();
......
......@@ -8,7 +8,7 @@ public class ServiceStackBenchmarks : BenchmarkBase
{
private IDbConnection _db;
[Setup]
[GlobalSetup]
public void Setup()
{
BaseSetup();
......
......@@ -6,7 +6,7 @@ public class SomaBenchmarks : BenchmarkBase
{
private dynamic _sdb;
[Setup]
[GlobalSetup]
public void Setup()
{
BaseSetup();
......
......@@ -18,7 +18,7 @@ public class SusanooBenchmarks : BenchmarkBase
.DefineResults<dynamic>()
.Realize();
[Setup]
[GlobalSetup]
public void Setup()
{
BaseSetup();
......
......@@ -12,25 +12,27 @@
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" />
<PackageReference Include="Belgrade.Sql.Client" Version="0.7.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.10.5" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.10.5" />
<PackageReference Include="BenchmarkDotNet" Version="0.10.9" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.10.9" />
<!--<PackageReference Include="BLToolkit" Version="4.3.6" />-->
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.9.0.1" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.9.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
<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="NHibernate" Version="4.1.1.4000" />
<PackageReference Include="Npgsql" Version="3.2.2" />
<PackageReference Include="PetaPoco" Version="5.1.244" />
<PackageReference Include="ServiceStack.OrmLite.SqlServer.Signed" Version="4.5.8" />
<PackageReference Include="Iesi.Collections" Version="4.0.2" />
<PackageReference Include="Npgsql" Version="3.2.5" />
<PackageReference Include="PetaPoco" Version="5.1.259" />
<PackageReference Include="ServiceStack.OrmLite.SqlServer.Signed" Version="4.5.12" />
<PackageReference Include="Simple.Data.SqlServer" Version="2.0.0-alpha1" />
<PackageReference Include="Soma" Version="1.9.0.1" />
<PackageReference Include="SubSonic" Version="3.0.0.4" />
<PackageReference Include="Susanoo.SqlServer" Version="1.2.4.2" />
<PackageReference Include="System.Data.SQLite" Version="1.0.105" />
<PackageReference Include="System.Data.SQLite" Version="1.0.105.2" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
......
......@@ -8,7 +8,7 @@ public class ORMColum : IColumn
{
public string Id => nameof(ORMColum);
public string ColumnName { get; } = "ORM";
public string Legend => "The object relational mapper being tested";
public string Legend => "The object/relational mapper being tested";
public bool IsDefault(Summary summary, Benchmark benchmark) => false;
public string GetValue(Summary summary, Benchmark benchmark) => benchmark.Target.Method.DeclaringType.Name.Replace("Benchmarks", string.Empty);
......
......@@ -341,7 +341,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()
{
......@@ -319,7 +319,7 @@ public async Task LiteralInAsync()
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();
......@@ -353,6 +353,12 @@ public void RunSequentialVersusParallelSync()
Console.WriteLine("Pipeline: {0}ms", watch.ElapsedMilliseconds);
}
[Collection(NonParallelDefinition.Name)]
public class AsyncQueryCacheTests : TestBase
{
private SqlConnection _marsConnection;
private SqlConnection MarsConnection => _marsConnection ?? (_marsConnection = GetOpenConnection(true));
[Fact]
public void AssertNoCacheWorksForQueryMultiple()
{
......@@ -376,6 +382,7 @@ public void AssertNoCacheWorksForQueryMultiple()
c.IsEqualTo(123);
d.IsEqualTo(456);
}
}
private class BasicType
{
......
......@@ -104,107 +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()
{
SqlMapper.AddTypeHandler(new Issue461_BlargHandler());
connection.Execute(@"CREATE TABLE #Issue461 (
Id int not null IDENTITY(1,1),
SomeValue nvarchar(50),
SomeBlargValue nvarchar(200),
)");
const string Expected = "abc123def";
var blarg = new Blarg(Expected);
connection.Execute(
"INSERT INTO #Issue461 (SomeValue, SomeBlargValue) VALUES (@value, @blarg)",
new { value = "what up?", blarg });
// test: without constructor
var parameterlessWorks = connection.QuerySingle<Issue461_ParameterlessTypeConstructor>("SELECT * FROM #Issue461");
parameterlessWorks.Id.IsEqualTo(1);
parameterlessWorks.SomeValue.IsEqualTo("what up?");
parameterlessWorks.SomeBlargValue.Value.IsEqualTo(Expected);
// test: via constructor
var parameterDoesNot = connection.QuerySingle<Issue461_ParameterisedTypeConstructor>("SELECT * FROM #Issue461");
parameterDoesNot.Id.IsEqualTo(1);
parameterDoesNot.SomeValue.IsEqualTo("what up?");
parameterDoesNot.SomeBlargValue.Value.IsEqualTo(Expected);
}
// I would usually expect this to be a struct; using a class
// so that we can't pass unexpectedly due to forcing an unsafe cast - want
// to see an InvalidCastException if it is wrong
private class Blarg
{
public Blarg(string value) { Value = value; }
public string Value { get; }
public override string ToString()
{
return Value;
}
}
private class Issue461_BlargHandler : SqlMapper.TypeHandler<Blarg>
{
public override void SetValue(IDbDataParameter parameter, Blarg value)
{
parameter.Value = ((object)value.Value) ?? DBNull.Value;
}
public override Blarg Parse(object value)
{
string s = (value == null || value is DBNull) ? null : Convert.ToString(value);
return new Blarg(s);
}
}
private class Issue461_ParameterlessTypeConstructor
{
public int Id { get; set; }
public string SomeValue { get; set; }
public Blarg SomeBlargValue { get; set; }
}
private class Issue461_ParameterisedTypeConstructor
{
public Issue461_ParameterisedTypeConstructor(int id, string someValue, Blarg someBlargValue)
{
Id = id;
SomeValue = someValue;
SomeBlargValue = someBlargValue;
}
public int Id { get; }
public string SomeValue { get; }
public Blarg SomeBlargValue { get; }
}
public static class AbstractInheritance
{
public abstract class Order
......
......@@ -6,14 +6,13 @@
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<TargetFrameworks>net452;netcoreapp1.0</TargetFrameworks>
<TargetFrameworks>net452;netcoreapp1.0;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp1.0</TargetFrameworks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</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 +20,22 @@
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.3.0" />
<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" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.9.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="MySql.Data" Version="8.0.8-dmr" />
<PackageReference Include="Npgsql" Version="3.2.5" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(xUnitVersion)" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<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.Data.Sqlite" Version="1.1.1" />
<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" />
......@@ -47,9 +45,12 @@
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="System.Ben" Version="1.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.0'">
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
......
......@@ -4,7 +4,7 @@
namespace Dapper.Tests
{
public partial class DataReaderTests : TestBase
public class DataReaderTests : TestBase
{
[Fact]
public void GetSameReaderForSameShape()
......@@ -137,18 +137,13 @@ private abstract class Discriminated_BaseType
private class Discriminated_Foo : Discriminated_BaseType
{
public string Name { get; set; }
public override int Type {
get { return 1; }
}
public override int Type => 1;
}
private class Discriminated_Bar : Discriminated_BaseType
{
public float Value { get; set; }
public override int Type
{
get { return 2; }
}
public override int Type => 2;
}
private abstract class DiscriminatedWithMultiMapping_BaseType : Discriminated_BaseType
......@@ -160,20 +155,14 @@ private class DiscriminatedWithMultiMapping_Foo : DiscriminatedWithMultiMapping_
{
public override HazNameId HazNameIdObject { get; set; }
public string Name { get; set; }
public override int Type
{
get { return 1; }
}
public override int Type => 1;
}
private class DiscriminatedWithMultiMapping_Bar : DiscriminatedWithMultiMapping_BaseType
{
public override HazNameId HazNameIdObject { get; set; }
public float Value { get; set; }
public override int Type
{
get { return 2; }
}
public override int Type => 2;
}
}
}
\ No newline at end of file
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()
{
......
......@@ -2,6 +2,7 @@
using System.Linq;
namespace Dapper.Tests
{
[Collection(NonParallelDefinition.Name)]
public class NullTests : TestBase
{
[Fact]
......
......@@ -10,6 +10,7 @@
using Xunit;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Diagnostics;
#if ENTITY_FRAMEWORK
using System.Data.Entity.Spatial;
......@@ -37,19 +38,8 @@ void SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, SqlMapper.Id
}
}
private class IntDynamicParam : SqlMapper.IDynamicParameters
{
private readonly IEnumerable<int> numbers;
public IntDynamicParam(IEnumerable<int> numbers)
private static List<Microsoft.SqlServer.Server.SqlDataRecord> CreateSqlDataRecordList(IEnumerable<int> numbers)
{
this.numbers = numbers;
}
public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
{
var sqlCommand = (SqlCommand)command;
sqlCommand.CommandType = CommandType.StoredProcedure;
var number_list = new List<Microsoft.SqlServer.Server.SqlDataRecord>();
// Create an SqlMetaData object that describes our table type.
......@@ -63,6 +53,24 @@ public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
number_list.Add(rec); // Add it to the list.
}
return number_list;
}
private class IntDynamicParam : SqlMapper.IDynamicParameters
{
private readonly IEnumerable<int> numbers;
public IntDynamicParam(IEnumerable<int> numbers)
{
this.numbers = numbers;
}
public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
{
var sqlCommand = (SqlCommand)command;
sqlCommand.CommandType = CommandType.StoredProcedure;
var number_list = CreateSqlDataRecordList(numbers);
// Add the table parameter.
var p = sqlCommand.Parameters.Add("ints", SqlDbType.Structured);
p.Direction = ParameterDirection.Input;
......@@ -84,18 +92,7 @@ public void AddParameter(IDbCommand command, string name)
var sqlCommand = (SqlCommand)command;
sqlCommand.CommandType = CommandType.StoredProcedure;
var number_list = new List<Microsoft.SqlServer.Server.SqlDataRecord>();
// Create an SqlMetaData object that describes our table type.
Microsoft.SqlServer.Server.SqlMetaData[] tvp_definition = { new Microsoft.SqlServer.Server.SqlMetaData("n", SqlDbType.Int) };
foreach (int n in numbers)
{
// Create a new record, using the metadata array above.
var rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvp_definition);
rec.SetInt32(0, n); // Set the value.
number_list.Add(rec); // Add it to the list.
}
var number_list = CreateSqlDataRecordList(numbers);
// Add the table parameter.
var p = sqlCommand.Parameters.Add(name, SqlDbType.Structured);
......@@ -217,7 +214,6 @@ public void TestMassiveStrings()
.IsEqualTo(str);
}
#if !COREFX
[Fact]
public void TestTVPWithAnonymousObject()
{
......@@ -288,18 +284,7 @@ public new void AddParameters(IDbCommand command, SqlMapper.Identity identity)
var sqlCommand = (SqlCommand)command;
sqlCommand.CommandType = CommandType.StoredProcedure;
var number_list = new List<Microsoft.SqlServer.Server.SqlDataRecord>();
// Create an SqlMetaData object that describes our table type.
Microsoft.SqlServer.Server.SqlMetaData[] tvp_definition = { new Microsoft.SqlServer.Server.SqlMetaData("n", SqlDbType.Int) };
foreach (int n in numbers)
{
// Create a new record, using the metadata array above.
var rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvp_definition);
rec.SetInt32(0, n); // Set the value.
number_list.Add(rec); // Add it to the list.
}
var number_list = CreateSqlDataRecordList(numbers);
// Add the table parameter.
var p = sqlCommand.Parameters.Add("ints", SqlDbType.Structured);
......@@ -343,6 +328,83 @@ public void TestTVPWithAdditionalParams()
}
}
[Fact]
public void TestSqlDataRecordListParametersWithAsTableValuedParameter()
{
try
{
connection.Execute("CREATE TYPE int_list_type AS TABLE (n int NOT NULL PRIMARY KEY)");
connection.Execute("CREATE PROC get_ints @integers int_list_type READONLY AS select * from @integers");
var records = CreateSqlDataRecordList(new int[] { 1, 2, 3 });
var nums = connection.Query<int>("get_ints", new { integers = records.AsTableValuedParameter() }, commandType: CommandType.StoredProcedure).ToList();
nums.IsSequenceEqualTo(new int[] { 1, 2, 3 });
nums = connection.Query<int>("select * from @integers", new { integers = records.AsTableValuedParameter("int_list_type") }).ToList();
nums.IsSequenceEqualTo(new int[] { 1, 2, 3 });
try
{
connection.Query<int>("select * from @integers", new { integers = records.AsTableValuedParameter() }).First();
throw new InvalidOperationException();
}
catch (Exception ex)
{
ex.Message.Equals("The table type parameter 'ids' must have a valid type name.");
}
}
finally
{
try
{
connection.Execute("DROP PROC get_ints");
}
finally
{
connection.Execute("DROP TYPE int_list_type");
}
}
}
[Fact]
public void TestSqlDataRecordListParametersWithTypeHandlers()
{
try
{
connection.Execute("CREATE TYPE int_list_type AS TABLE (n int NOT NULL PRIMARY KEY)");
connection.Execute("CREATE PROC get_ints @integers int_list_type READONLY AS select * from @integers");
// Variable type has to be IEnumerable<SqlDataRecord> for TypeHandler to kick in.
IEnumerable<Microsoft.SqlServer.Server.SqlDataRecord> records = CreateSqlDataRecordList(new int[] { 1, 2, 3 });
var nums = connection.Query<int>("get_ints", new { integers = records }, commandType: CommandType.StoredProcedure).ToList();
nums.IsSequenceEqualTo(new int[] { 1, 2, 3 });
try
{
connection.Query<int>("select * from @integers", new { integers = records }).First();
throw new InvalidOperationException();
}
catch (Exception ex)
{
ex.Message.Equals("The table type parameter 'ids' must have a valid type name.");
}
}
finally
{
try
{
connection.Execute("DROP PROC get_ints");
}
finally
{
connection.Execute("DROP TYPE int_list_type");
}
}
}
#if !NETCOREAPP1_0
[Fact]
public void DataTableParameters()
{
......@@ -491,7 +553,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 +562,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
......
......@@ -4,6 +4,7 @@
namespace Dapper.Tests.Providers
{
[Collection("TypeHandlerTests")]
public class EntityFrameworkTests : TestBase
{
public EntityFrameworkTests()
......
#if FIREBIRD
using FirebirdSql.Data.FirebirdClient;
using FirebirdSql.Data.FirebirdClient;
using System.Data;
using System.Linq;
using Xunit;
......@@ -46,4 +45,3 @@ public void Issue178_Firebird()
}
}
}
\ No newline at end of file
#endif
\ 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;
......@@ -186,4 +185,3 @@ static FactMySqlAttribute()
}
}
}
#endif
#if POSTGRESQL
using System;
using System;
using System.Data;
using System.Linq;
using Xunit;
......@@ -81,4 +80,3 @@ static FactPostgresqlAttribute()
}
}
}
\ No newline at end of file
#endif
\ 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;
}
......@@ -26,6 +24,9 @@ public void DapperEnumValue_Sqlite()
}
}
[Collection(NonParallelDefinition.Name)]
public class SqliteTypeHandlerTests : TestBase
{
[FactSqlite]
public void Issue466_SqliteHatesOptimizations()
{
......@@ -63,6 +64,7 @@ public async Task Issue466_SqliteHatesOptimizations_Async()
row.Id.IsEqualTo(42);
}
}
}
[FactSqlite]
public void Isse467_SqliteLikesParametersWithPrefix()
......@@ -82,11 +84,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);
......@@ -119,4 +117,3 @@ static FactSqliteAttribute()
}
}
}
\ No newline at end of file
#endif
\ No newline at end of file
......@@ -2,7 +2,8 @@
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
#if !COREFX
using Xunit;
#if !NETCOREAPP1_0
using System.Threading;
#endif
......@@ -45,7 +46,7 @@ public SqlConnection GetClosedConnection()
protected static CultureInfo ActiveCulture
{
#if COREFX
#if NETCOREAPP1_0
get { return CultureInfo.CurrentCulture; }
set { CultureInfo.CurrentCulture = value; }
#else
......@@ -58,8 +59,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...");
......@@ -81,4 +82,10 @@ public void Dispose()
_connection?.Dispose();
}
}
[CollectionDefinition(Name, DisableParallelization = true)]
public class NonParallelDefinition : TestBase
{
public const string Name = "NonParallel";
}
}
......@@ -8,6 +8,7 @@
namespace Dapper.Tests
{
[Collection(NonParallelDefinition.Name)]
public class TypeHandlerTests : TestBase
{
[Fact]
......@@ -48,6 +49,51 @@ public void TestChangingDefaultStringTypeMappingToAnsiStringFirstOrDefault()
SqlMapper.AddTypeMap(typeof(string), DbType.String); // Restore Default to Unicode String
}
[Fact]
public void TestCustomTypeMap()
{
// default mapping
var item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item.A.IsEqualTo("AVal");
item.B.IsEqualTo("BVal");
// custom mapping
var map = new CustomPropertyTypeMap(typeof(TypeWithMapping),
(type, columnName) => type.GetProperties().FirstOrDefault(prop => GetDescriptionFromAttribute(prop) == columnName));
SqlMapper.SetTypeMap(typeof(TypeWithMapping), map);
item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item.A.IsEqualTo("BVal");
item.B.IsEqualTo("AVal");
// reset to default
SqlMapper.SetTypeMap(typeof(TypeWithMapping), null);
item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item.A.IsEqualTo("AVal");
item.B.IsEqualTo("BVal");
}
private static string GetDescriptionFromAttribute(MemberInfo member)
{
if (member == null) return null;
#if NETCOREAPP1_0
var data = member.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(DescriptionAttribute));
return (string)data?.ConstructorArguments.Single().Value;
#else
var attrib = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(DescriptionAttribute), false);
return attrib?.Description;
#endif
}
public class TypeWithMapping
{
[Description("B")]
public string A { get; set; }
[Description("A")]
public string B { get; set; }
}
[Fact]
public void Issue136_ValueTypeHandlers()
{
......@@ -230,52 +276,52 @@ private void TestBigIntForEverythingWorks_ByDataType<T>(string dbType)
row.N_P_Long.Value.IsEqualTo(LotsOfNumerics.E_Long.B);
row.N_P_ULong.Value.IsEqualTo(LotsOfNumerics.E_ULong.B);
TestBigIntForEverythingWorks<bool>(true, dbType);
TestBigIntForEverythingWorks<sbyte>((sbyte)1, dbType);
TestBigIntForEverythingWorks<byte>((byte)1, dbType);
TestBigIntForEverythingWorks<int>((int)1, dbType);
TestBigIntForEverythingWorks<uint>((uint)1, dbType);
TestBigIntForEverythingWorks<short>((short)1, dbType);
TestBigIntForEverythingWorks<ushort>((ushort)1, dbType);
TestBigIntForEverythingWorks<long>((long)1, dbType);
TestBigIntForEverythingWorks<ulong>((ulong)1, dbType);
TestBigIntForEverythingWorks<float>((float)1, dbType);
TestBigIntForEverythingWorks<double>((double)1, dbType);
TestBigIntForEverythingWorks<decimal>((decimal)1, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_Byte.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_SByte.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_Int.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_UInt.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_Short.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_UShort.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_Long.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_ULong.B, dbType);
TestBigIntForEverythingWorks<bool?>(true, dbType);
TestBigIntForEverythingWorks<sbyte?>((sbyte)1, dbType);
TestBigIntForEverythingWorks<byte?>((byte)1, dbType);
TestBigIntForEverythingWorks<int?>((int)1, dbType);
TestBigIntForEverythingWorks<uint?>((uint)1, dbType);
TestBigIntForEverythingWorks<short?>((short)1, dbType);
TestBigIntForEverythingWorks<ushort?>((ushort)1, dbType);
TestBigIntForEverythingWorks<long?>((long)1, dbType);
TestBigIntForEverythingWorks<ulong?>((ulong)1, dbType);
TestBigIntForEverythingWorks<float?>((float)1, dbType);
TestBigIntForEverythingWorks<double?>((double)1, dbType);
TestBigIntForEverythingWorks<decimal?>((decimal)1, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_Byte?>(LotsOfNumerics.E_Byte.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_SByte?>(LotsOfNumerics.E_SByte.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_Int?>(LotsOfNumerics.E_Int.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_UInt?>(LotsOfNumerics.E_UInt.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_Short?>(LotsOfNumerics.E_Short.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_UShort?>(LotsOfNumerics.E_UShort.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_Long?>(LotsOfNumerics.E_Long.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_ULong?>(LotsOfNumerics.E_ULong.B, dbType);
}
private void TestBigIntForEverythingWorks<T>(T expected, string dbType)
TestBigIntForEverythingWorksGeneric<bool>(true, dbType);
TestBigIntForEverythingWorksGeneric<sbyte>((sbyte)1, dbType);
TestBigIntForEverythingWorksGeneric<byte>((byte)1, dbType);
TestBigIntForEverythingWorksGeneric<int>((int)1, dbType);
TestBigIntForEverythingWorksGeneric<uint>((uint)1, dbType);
TestBigIntForEverythingWorksGeneric<short>((short)1, dbType);
TestBigIntForEverythingWorksGeneric<ushort>((ushort)1, dbType);
TestBigIntForEverythingWorksGeneric<long>((long)1, dbType);
TestBigIntForEverythingWorksGeneric<ulong>((ulong)1, dbType);
TestBigIntForEverythingWorksGeneric<float>((float)1, dbType);
TestBigIntForEverythingWorksGeneric<double>((double)1, dbType);
TestBigIntForEverythingWorksGeneric<decimal>((decimal)1, dbType);
TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_Byte.B, dbType);
TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_SByte.B, dbType);
TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_Int.B, dbType);
TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_UInt.B, dbType);
TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_Short.B, dbType);
TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_UShort.B, dbType);
TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_Long.B, dbType);
TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_ULong.B, dbType);
TestBigIntForEverythingWorksGeneric<bool?>(true, dbType);
TestBigIntForEverythingWorksGeneric<sbyte?>((sbyte)1, dbType);
TestBigIntForEverythingWorksGeneric<byte?>((byte)1, dbType);
TestBigIntForEverythingWorksGeneric<int?>((int)1, dbType);
TestBigIntForEverythingWorksGeneric<uint?>((uint)1, dbType);
TestBigIntForEverythingWorksGeneric<short?>((short)1, dbType);
TestBigIntForEverythingWorksGeneric<ushort?>((ushort)1, dbType);
TestBigIntForEverythingWorksGeneric<long?>((long)1, dbType);
TestBigIntForEverythingWorksGeneric<ulong?>((ulong)1, dbType);
TestBigIntForEverythingWorksGeneric<float?>((float)1, dbType);
TestBigIntForEverythingWorksGeneric<double?>((double)1, dbType);
TestBigIntForEverythingWorksGeneric<decimal?>((decimal)1, dbType);
TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_Byte?>(LotsOfNumerics.E_Byte.B, dbType);
TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_SByte?>(LotsOfNumerics.E_SByte.B, dbType);
TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_Int?>(LotsOfNumerics.E_Int.B, dbType);
TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_UInt?>(LotsOfNumerics.E_UInt.B, dbType);
TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_Short?>(LotsOfNumerics.E_Short.B, dbType);
TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_UShort?>(LotsOfNumerics.E_UShort.B, dbType);
TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_Long?>(LotsOfNumerics.E_Long.B, dbType);
TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_ULong?>(LotsOfNumerics.E_ULong.B, dbType);
}
private void TestBigIntForEverythingWorksGeneric<T>(T expected, string dbType)
{
var query = connection.Query<T>("select cast(1 as " + dbType + ")").Single();
query.IsEqualTo(expected);
......@@ -462,7 +508,7 @@ public void Test_RemoveTypeMap()
try
{
connection.Execute(@"INSERT INTO #Test_RemoveTypeMap VALUES (@Now)", new { DateTime.Now });
connection.Execute("INSERT INTO #Test_RemoveTypeMap VALUES (@Now)", new { DateTime.Now });
connection.Query<DateTime>("SELECT * FROM #Test_RemoveTypeMap");
dateTimeHandler.ParseWasCalled.IsTrue();
......@@ -518,51 +564,6 @@ private class ResultsChangeType
public int Z { get; set; }
}
[Fact]
public void TestCustomTypeMap()
{
// default mapping
var item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item.A.IsEqualTo("AVal");
item.B.IsEqualTo("BVal");
// custom mapping
var map = new CustomPropertyTypeMap(typeof(TypeWithMapping),
(type, columnName) => type.GetProperties().FirstOrDefault(prop => GetDescriptionFromAttribute(prop) == columnName));
SqlMapper.SetTypeMap(typeof(TypeWithMapping), map);
item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item.A.IsEqualTo("BVal");
item.B.IsEqualTo("AVal");
// reset to default
SqlMapper.SetTypeMap(typeof(TypeWithMapping), null);
item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item.A.IsEqualTo("AVal");
item.B.IsEqualTo("BVal");
}
private static string GetDescriptionFromAttribute(MemberInfo member)
{
if (member == null) return null;
#if COREFX
var data = member.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(DescriptionAttribute));
return (string)data?.ConstructorArguments.Single().Value;
#else
var attrib = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(DescriptionAttribute), false);
return attrib?.Description;
#endif
}
public class TypeWithMapping
{
[Description("B")]
public string A { get; set; }
[Description("A")]
public string B { get; set; }
}
public class WrongTypes
{
public int A { get; set; }
......@@ -634,7 +635,7 @@ public void Issue149_TypeMismatch_SequentialAccess()
Guid guid = Guid.Parse("cf0ef7ac-b6fe-4e24-aeda-a2b45bb5654e");
try
{
var result = connection.Query<Issue149_Person>(@"select @guid as Id", new { guid }).First();
var result = connection.Query<Issue149_Person>("select @guid as Id", new { guid }).First();
error = null;
}
catch (Exception ex)
......@@ -658,5 +659,84 @@ public void SO29343103_UtcDates()
var delta = returned - date;
Assert.IsTrue(delta.TotalMilliseconds >= -10 && delta.TotalMilliseconds <= 10);
}
[Fact]
public void Issue461_TypeHandlerWorksInConstructor()
{
SqlMapper.AddTypeHandler(new Issue461_BlargHandler());
connection.Execute(@"CREATE TABLE #Issue461 (
Id int not null IDENTITY(1,1),
SomeValue nvarchar(50),
SomeBlargValue nvarchar(200),
)");
const string Expected = "abc123def";
var blarg = new Blarg(Expected);
connection.Execute(
"INSERT INTO #Issue461 (SomeValue, SomeBlargValue) VALUES (@value, @blarg)",
new { value = "what up?", blarg });
// test: without constructor
var parameterlessWorks = connection.QuerySingle<Issue461_ParameterlessTypeConstructor>("SELECT * FROM #Issue461");
parameterlessWorks.Id.IsEqualTo(1);
parameterlessWorks.SomeValue.IsEqualTo("what up?");
parameterlessWorks.SomeBlargValue.Value.IsEqualTo(Expected);
// test: via constructor
var parameterDoesNot = connection.QuerySingle<Issue461_ParameterisedTypeConstructor>("SELECT * FROM #Issue461");
parameterDoesNot.Id.IsEqualTo(1);
parameterDoesNot.SomeValue.IsEqualTo("what up?");
parameterDoesNot.SomeBlargValue.Value.IsEqualTo(Expected);
}
// I would usually expect this to be a struct; using a class
// so that we can't pass unexpectedly due to forcing an unsafe cast - want
// to see an InvalidCastException if it is wrong
private class Blarg
{
public Blarg(string value) { Value = value; }
public string Value { get; }
public override string ToString()
{
return Value;
}
}
private class Issue461_BlargHandler : SqlMapper.TypeHandler<Blarg>
{
public override void SetValue(IDbDataParameter parameter, Blarg value)
{
parameter.Value = ((object)value.Value) ?? DBNull.Value;
}
public override Blarg Parse(object value)
{
string s = (value == null || value is DBNull) ? null : Convert.ToString(value);
return new Blarg(s);
}
}
private class Issue461_ParameterlessTypeConstructor
{
public int Id { get; set; }
public string SomeValue { get; set; }
public Blarg SomeBlargValue { get; set; }
}
private class Issue461_ParameterisedTypeConstructor
{
public Issue461_ParameterisedTypeConstructor(int id, string someValue, Blarg someBlargValue)
{
Id = id;
SomeValue = someValue;
SomeBlargValue = someBlargValue;
}
public int Id { get; }
public string SomeValue { get; }
public Blarg SomeBlargValue { get; }
}
}
}

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.7
VisualStudioVersion = 15.0.26730.8
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A34907DF-958A-4E4C-8491-84CF303FD13E}"
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
build.ps1 = build.ps1
build.sh = build.sh
Directory.build.props = Directory.build.props
License.txt = License.txt
nuget.config = nuget.config
Readme.md = Readme.md
semver.txt = semver.txt
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapper", "Dapper\Dapper.csproj", "{FAC24C3F-68F9-4247-A4B9-21D487E99275}"
......@@ -101,4 +103,7 @@ Global
{39D3EEB6-9C05-4F4A-8C01-7B209742A7EB} = {4E956F6B-6BD8-46F5-BC85-49292FF8F9AB}
{F017075A-2969-4A8E-8971-26F154EB420F} = {568BD46C-1C65-4D44-870C-12CD72563262}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {928A4226-96F3-409A-8A83-9E7444488710}
EndGlobalSection
EndGlobal
......@@ -5,9 +5,9 @@
<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>net451;netstandard1.3;netstandard2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451' ">
<ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
......@@ -17,7 +17,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
<PackageReference Include="System.Data.Common" Version="4.3.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.3.0" />
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
......@@ -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" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.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,6 @@
using System.Collections.Generic;
using System.Data;
#if !COREFX
namespace Dapper
{
internal sealed class SqlDataRecordHandler : SqlMapper.ITypeHandler
......@@ -18,4 +17,3 @@ public void SetValue(IDbDataParameter parameter, object value)
}
}
}
#endif
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
#if !COREFX
namespace Dapper
{
/// <summary>
......@@ -23,18 +22,6 @@ public SqlDataRecordListTVPParameter(IEnumerable<Microsoft.SqlServer.Server.SqlD
this.typeName = typeName;
}
private static readonly Action<System.Data.SqlClient.SqlParameter, string> setTypeName;
static SqlDataRecordListTVPParameter()
{
var prop = typeof(System.Data.SqlClient.SqlParameter).GetProperty(nameof(System.Data.SqlClient.SqlParameter.TypeName), BindingFlags.Instance | BindingFlags.Public);
if (prop != null && prop.PropertyType == typeof(string) && prop.CanWrite)
{
setTypeName = (Action<System.Data.SqlClient.SqlParameter, string>)
Delegate.CreateDelegate(typeof(Action<System.Data.SqlClient.SqlParameter, string>), prop.GetSetMethod());
}
}
void SqlMapper.ICustomQueryParameter.AddParameter(IDbCommand command, string name)
{
var param = command.CreateParameter();
......@@ -54,4 +41,3 @@ internal static void Set(IDbDataParameter parameter, IEnumerable<Microsoft.SqlSe
}
}
}
#endif
\ No newline at end of file
......@@ -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,26 +217,24 @@ static SqlMapper()
private static void ResetTypeHandlers(bool clone)
{
typeHandlers = new Dictionary<Type, ITypeHandler>();
#if !COREFX
#if !NETSTANDARD1_3
AddTypeHandlerImpl(typeof(DataTable), new DataTableHandler(), clone);
#endif
try
{
AddSqlDataRecordsTypeHandler(clone);
}
catch { /* https://github.com/StackExchange/dapper-dot-net/issues/424 */ }
#endif
AddTypeHandlerImpl(typeof(XmlDocument), new XmlDocumentHandler(), clone);
AddTypeHandlerImpl(typeof(XDocument), new XDocumentHandler(), clone);
AddTypeHandlerImpl(typeof(XElement), new XElementHandler(), clone);
}
#if !COREFX
[MethodImpl(MethodImplOptions.NoInlining)]
private static void AddSqlDataRecordsTypeHandler(bool clone)
{
AddTypeHandlerImpl(typeof(IEnumerable<Microsoft.SqlServer.Server.SqlDataRecord>), new SqlDataRecordHandler(), clone);
}
#endif
/// <summary>
/// Configure the specified type to be mapped to a given db-type.
......@@ -348,7 +346,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 +365,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 +395,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 +1862,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 +1879,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 +1898,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 +1956,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 +2255,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 +3078,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 +3113,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 +3135,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 +3352,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 +3624,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>
......@@ -3662,15 +3660,15 @@ public static void SetTypeName(this DataTable table, string typeName)
/// <param name="table">The <see cref="DataTable"/> that has a type name associated with it.</param>
public static string GetTypeName(this DataTable table) =>
table?.ExtendedProperties[DataTableTypeNameKey] as string;
#endif
/// <summary>
/// Used to pass a IEnumerable&lt;SqlDataRecord&gt; as a <see cref="TableValuedParameter"/>.
/// Used to pass a IEnumerable&lt;SqlDataRecord&gt; as a TableValuedParameter.
/// </summary>
/// <param name="list">Thhe list of records to convert to TVPs.</param>
/// <param name="list">The list of records to convert to TVPs.</param>
/// <param name="typeName">The sql parameter type name.</param>
public static ICustomQueryParameter AsTableValuedParameter(this IEnumerable<Microsoft.SqlServer.Server.SqlDataRecord> list, string typeName = null) =>
new SqlDataRecordListTVPParameter(list, typeName);
#endif
// one per thread
[ThreadStatic]
......
......@@ -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
......
......@@ -19,28 +19,20 @@
<DebugType>embedded</DebugType>
<DefaultLanguage>en-US</DefaultLanguage>
<IncludeSymbols>false</IncludeSymbols>
<xUnitVersion>2.3.0-beta5-build3750</xUnitVersion>
</PropertyGroup>
<!-- Workarounds for https://github.com/NuGet/Home/issues/4853 -->
<PropertyGroup Condition="'$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451'">
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451'">
<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" />
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="4.3.0-preview1-4045" PrivateAssets="All" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.0.2" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.0.2" />
<PackageReference Include="SourceLink.Create.GitHub" Version="2.1.2" PrivateAssets="All" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.1.2" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.1.2" />
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="xUnit" value="https://www.myget.org/F/xunit/api/v3/index.json" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
\ No newline at end of file
1.50.3-alpha1
\ No newline at end of file
1.50.4-alpha1
\ No newline at end of file
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