Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Dapper
提交
8152f2c7
D
Dapper
项目概览
int
/
Dapper
9 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Dapper
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
8152f2c7
编写于
8月 28, 2019
作者:
M
Marc Gravell
提交者:
GitHub
8月 28, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WIP: Lib updates and prepare for Microsoft.Data.SqlClient (#1313)
v2 work; primarily prep for split SqlClient
上级
6df95cbd
变更
56
隐藏空白更改
内联
并排
Showing
56 changed file
with
633 addition
and
568 deletion
+633
-568
Dapper.Contrib/Dapper.Contrib.csproj
Dapper.Contrib/Dapper.Contrib.csproj
+2
-11
Dapper.Contrib/SqlMapperExtensions.Async.cs
Dapper.Contrib/SqlMapperExtensions.Async.cs
+10
-10
Dapper.Contrib/SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+11
-11
Dapper.EntityFramework.StrongName/Dapper.EntityFramework.StrongName.csproj
...ework.StrongName/Dapper.EntityFramework.StrongName.csproj
+3
-8
Dapper.EntityFramework/Dapper.EntityFramework.csproj
Dapper.EntityFramework/Dapper.EntityFramework.csproj
+3
-8
Dapper.Rainbow/Dapper.Rainbow.csproj
Dapper.Rainbow/Dapper.Rainbow.csproj
+4
-10
Dapper.Rainbow/Database.cs
Dapper.Rainbow/Database.cs
+1
-1
Dapper.Rainbow/Snapshotter.cs
Dapper.Rainbow/Snapshotter.cs
+17
-17
Dapper.SqlBuilder/Dapper.SqlBuilder.csproj
Dapper.SqlBuilder/Dapper.SqlBuilder.csproj
+4
-10
Dapper.StrongName/Dapper.StrongName.csproj
Dapper.StrongName/Dapper.StrongName.csproj
+3
-25
Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj
Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj
+10
-6
Dapper.Tests.Contrib/TestSuite.cs
Dapper.Tests.Contrib/TestSuite.cs
+6
-11
Dapper.Tests.Contrib/TestSuites.cs
Dapper.Tests.Contrib/TestSuites.cs
+3
-6
Dapper.Tests.Performance/Config.cs
Dapper.Tests.Performance/Config.cs
+5
-5
Dapper.Tests.Performance/Dapper.Tests.Performance.csproj
Dapper.Tests.Performance/Dapper.Tests.Performance.csproj
+12
-12
Dapper.Tests.Performance/Helpers/ORMColum.cs
Dapper.Tests.Performance/Helpers/ORMColum.cs
+1
-1
Dapper.Tests.Performance/Helpers/ReturnColum.cs
Dapper.Tests.Performance/Helpers/ReturnColum.cs
+1
-1
Dapper.Tests/App.config
Dapper.Tests/App.config
+11
-0
Dapper.Tests/AsyncTests.cs
Dapper.Tests/AsyncTests.cs
+13
-4
Dapper.Tests/ConstructorTests.cs
Dapper.Tests/ConstructorTests.cs
+2
-0
Dapper.Tests/Dapper.Tests.csproj
Dapper.Tests/Dapper.Tests.csproj
+37
-31
Dapper.Tests/DataReaderTests.cs
Dapper.Tests/DataReaderTests.cs
+2
-0
Dapper.Tests/DecimalTests.cs
Dapper.Tests/DecimalTests.cs
+2
-0
Dapper.Tests/EnumTests.cs
Dapper.Tests/EnumTests.cs
+2
-0
Dapper.Tests/Helpers/Attributes.cs
Dapper.Tests/Helpers/Attributes.cs
+29
-1
Dapper.Tests/Helpers/XunitSkippable.cs
Dapper.Tests/Helpers/XunitSkippable.cs
+96
-40
Dapper.Tests/LiteralTests.cs
Dapper.Tests/LiteralTests.cs
+2
-0
Dapper.Tests/MiscTests.cs
Dapper.Tests/MiscTests.cs
+2
-0
Dapper.Tests/MultiMapTests.cs
Dapper.Tests/MultiMapTests.cs
+2
-0
Dapper.Tests/ParameterTests.cs
Dapper.Tests/ParameterTests.cs
+90
-31
Dapper.Tests/ProcedureTests.cs
Dapper.Tests/ProcedureTests.cs
+2
-0
Dapper.Tests/Providers/EntityFrameworkTests.cs
Dapper.Tests/Providers/EntityFrameworkTests.cs
+4
-0
Dapper.Tests/QueryMultipleTests.cs
Dapper.Tests/QueryMultipleTests.cs
+2
-0
Dapper.Tests/TestBase.cs
Dapper.Tests/TestBase.cs
+3
-0
Dapper.Tests/TransactionTests.cs
Dapper.Tests/TransactionTests.cs
+2
-0
Dapper.Tests/TupleTests.cs
Dapper.Tests/TupleTests.cs
+2
-0
Dapper.Tests/XmlTests.cs
Dapper.Tests/XmlTests.cs
+2
-0
Dapper.sln
Dapper.sln
+1
-0
Dapper/Dapper.csproj
Dapper/Dapper.csproj
+3
-25
Dapper/DataTableHandler.cs
Dapper/DataTableHandler.cs
+0
-2
Dapper/DefaultTypeMap.cs
Dapper/DefaultTypeMap.cs
+4
-25
Dapper/DynamicParameters.cs
Dapper/DynamicParameters.cs
+0
-4
Dapper/SqlDataRecordHandler.cs
Dapper/SqlDataRecordHandler.cs
+0
-2
Dapper/SqlDataRecordListTVPParameter.cs
Dapper/SqlDataRecordListTVPParameter.cs
+0
-2
Dapper/SqlMapper.Async.cs
Dapper/SqlMapper.Async.cs
+9
-9
Dapper/SqlMapper.DapperRow.Descriptor.cs
Dapper/SqlMapper.DapperRow.Descriptor.cs
+1
-3
Dapper/SqlMapper.GridReader.cs
Dapper/SqlMapper.GridReader.cs
+1
-9
Dapper/SqlMapper.IDataReader.cs
Dapper/SqlMapper.IDataReader.cs
+1
-1
Dapper/SqlMapper.Identity.cs
Dapper/SqlMapper.Identity.cs
+123
-16
Dapper/SqlMapper.TypeHandlerCache.cs
Dapper/SqlMapper.TypeHandlerCache.cs
+0
-2
Dapper/SqlMapper.cs
Dapper/SqlMapper.cs
+82
-114
Dapper/TableValuedParameter.cs
Dapper/TableValuedParameter.cs
+0
-2
Dapper/TypeExtensions.cs
Dapper/TypeExtensions.cs
+1
-86
Dapper/UdtTypeHandler.cs
Dapper/UdtTypeHandler.cs
+0
-2
Directory.build.props
Directory.build.props
+2
-2
version.json
version.json
+2
-2
未找到文件。
Dapper.Contrib/Dapper.Contrib.csproj
浏览文件 @
8152f2c7
...
...
@@ -5,8 +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>net451;netstandard1.3;netstandard2.0</TargetFrameworks>
<!-- TODO: Docs -->
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
...
...
@@ -15,16 +14,8 @@
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup>
<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' OR '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
</ItemGroup>
</Project>
\ No newline at end of file
Dapper.Contrib/SqlMapperExtensions.Async.cs
浏览文件 @
8152f2c7
...
...
@@ -37,7 +37,7 @@ public static partial class SqlMapperExtensions
var
dynParms
=
new
DynamicParameters
();
dynParms
.
Add
(
"@id"
,
id
);
if
(!
type
.
IsInterface
()
)
if
(!
type
.
IsInterface
)
return
(
await
connection
.
QueryAsync
<
T
>(
sql
,
dynParms
,
transaction
,
commandTimeout
).
ConfigureAwait
(
false
)).
FirstOrDefault
();
var
res
=
(
await
connection
.
QueryAsync
<
dynamic
>(
sql
,
dynParms
).
ConfigureAwait
(
false
)).
FirstOrDefault
()
as
IDictionary
<
string
,
object
>;
...
...
@@ -51,7 +51,7 @@ public static partial class SqlMapperExtensions
{
var
val
=
res
[
property
.
Name
];
if
(
val
==
null
)
continue
;
if
(
property
.
PropertyType
.
IsGenericType
()
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
if
(
property
.
PropertyType
.
IsGenericType
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
{
var
genericType
=
Nullable
.
GetUnderlyingType
(
property
.
PropertyType
);
if
(
genericType
!=
null
)
property
.
SetValue
(
obj
,
Convert
.
ChangeType
(
val
,
genericType
),
null
);
...
...
@@ -92,7 +92,7 @@ public static partial class SqlMapperExtensions
GetQueries
[
cacheType
.
TypeHandle
]
=
sql
;
}
if
(!
type
.
IsInterface
()
)
if
(!
type
.
IsInterface
)
{
return
connection
.
QueryAsync
<
T
>(
sql
,
null
,
transaction
,
commandTimeout
);
}
...
...
@@ -110,7 +110,7 @@ public static partial class SqlMapperExtensions
{
var
val
=
res
[
property
.
Name
];
if
(
val
==
null
)
continue
;
if
(
property
.
PropertyType
.
IsGenericType
()
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
if
(
property
.
PropertyType
.
IsGenericType
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
{
var
genericType
=
Nullable
.
GetUnderlyingType
(
property
.
PropertyType
);
if
(
genericType
!=
null
)
property
.
SetValue
(
obj
,
Convert
.
ChangeType
(
val
,
genericType
),
null
);
...
...
@@ -148,11 +148,11 @@ public static partial class SqlMapperExtensions
isList
=
true
;
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
()
)
else
if
(
type
.
IsGenericType
)
{
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
...
...
@@ -219,11 +219,11 @@ public static partial class SqlMapperExtensions
{
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
()
)
else
if
(
type
.
IsGenericType
)
{
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
...
...
@@ -288,11 +288,11 @@ public static partial class SqlMapperExtensions
{
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
()
)
else
if
(
type
.
IsGenericType
)
{
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
...
...
Dapper.Contrib/SqlMapperExtensions.cs
浏览文件 @
8152f2c7
...
...
@@ -190,7 +190,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
T
obj
;
if
(
type
.
IsInterface
()
)
if
(
type
.
IsInterface
)
{
var
res
=
connection
.
Query
(
sql
,
dynParms
).
FirstOrDefault
()
as
IDictionary
<
string
,
object
>;
...
...
@@ -203,7 +203,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
{
var
val
=
res
[
property
.
Name
];
if
(
val
==
null
)
continue
;
if
(
property
.
PropertyType
.
IsGenericType
()
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
if
(
property
.
PropertyType
.
IsGenericType
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
{
var
genericType
=
Nullable
.
GetUnderlyingType
(
property
.
PropertyType
);
if
(
genericType
!=
null
)
property
.
SetValue
(
obj
,
Convert
.
ChangeType
(
val
,
genericType
),
null
);
...
...
@@ -248,7 +248,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
GetQueries
[
cacheType
.
TypeHandle
]
=
sql
;
}
if
(!
type
.
IsInterface
()
)
return
connection
.
Query
<
T
>(
sql
,
null
,
transaction
,
commandTimeout
:
commandTimeout
);
if
(!
type
.
IsInterface
)
return
connection
.
Query
<
T
>(
sql
,
null
,
transaction
,
commandTimeout
:
commandTimeout
);
var
result
=
connection
.
Query
(
sql
);
var
list
=
new
List
<
T
>();
...
...
@@ -259,7 +259,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
{
var
val
=
res
[
property
.
Name
];
if
(
val
==
null
)
continue
;
if
(
property
.
PropertyType
.
IsGenericType
()
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
if
(
property
.
PropertyType
.
IsGenericType
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
{
var
genericType
=
Nullable
.
GetUnderlyingType
(
property
.
PropertyType
);
if
(
genericType
!=
null
)
property
.
SetValue
(
obj
,
Convert
.
ChangeType
(
val
,
genericType
),
null
);
...
...
@@ -307,7 +307,7 @@ private static string GetTableName(Type type)
else
{
name
=
type
.
Name
+
"s"
;
if
(
type
.
IsInterface
()
&&
name
.
StartsWith
(
"I"
))
if
(
type
.
IsInterface
&&
name
.
StartsWith
(
"I"
))
name
=
name
.
Substring
(
1
);
}
}
...
...
@@ -336,11 +336,11 @@ private static string GetTableName(Type type)
isList
=
true
;
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
()
)
else
if
(
type
.
IsGenericType
)
{
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
...
...
@@ -417,11 +417,11 @@ private static string GetTableName(Type type)
{
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
()
)
else
if
(
type
.
IsGenericType
)
{
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
...
...
@@ -486,11 +486,11 @@ private static string GetTableName(Type type)
{
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
()
)
else
if
(
type
.
IsGenericType
)
{
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
...
...
Dapper.EntityFramework.StrongName/Dapper.EntityFramework.StrongName.csproj
浏览文件 @
8152f2c7
...
...
@@ -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>net4
51
</TargetFrameworks>
<TargetFrameworks>net4
62
</TargetFrameworks>
<AssemblyOriginatorKeyFile>../Dapper.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
...
...
@@ -16,13 +16,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper.StrongName\Dapper.StrongName.csproj" />
<!-- note: 6.2.0 has regressions; don't force the update -->
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="11.0.2" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Xml" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.1016.290" />
</ItemGroup>
</Project>
Dapper.EntityFramework/Dapper.EntityFramework.csproj
浏览文件 @
8152f2c7
...
...
@@ -5,18 +5,13 @@
<AssemblyTitle>Dapper entity framework type handlers</AssemblyTitle>
<VersionPrefix>1.50.2</VersionPrefix>
<Authors>Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net4
51
</TargetFrameworks>
<TargetFrameworks>net4
62
</TargetFrameworks>
<PackageTags>orm;sql;micro-orm</PackageTags>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<!-- note: 6.2.0 has regressions; don't force the update -->
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="11.0.2" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Xml" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.1016.290" />
</ItemGroup>
</Project>
\ No newline at end of file
Dapper.Rainbow/Dapper.Rainbow.csproj
浏览文件 @
8152f2c7
...
...
@@ -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>net
451;netstandard1.3
</TargetFrameworks>
<TargetFrameworks>net
standard2.0
</TargetFrameworks>
<!-- TODO: Docs -->
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
...
...
@@ -16,14 +16,8 @@
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup>
<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'">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
</ItemGroup>
</Project>
\ No newline at end of file
Dapper.Rainbow/Database.cs
浏览文件 @
8152f2c7
...
...
@@ -257,7 +257,7 @@ protected Action<TDatabase> CreateTableConstructor(params Type[] tableTypes)
var
il
=
dm
.
GetILGenerator
();
var
setters
=
GetType
().
GetProperties
()
.
Where
(
p
=>
p
.
PropertyType
.
IsGenericType
()
&&
tableTypes
.
Contains
(
p
.
PropertyType
.
GetGenericTypeDefinition
()))
.
Where
(
p
=>
p
.
PropertyType
.
IsGenericType
&&
tableTypes
.
Contains
(
p
.
PropertyType
.
GetGenericTypeDefinition
()))
.
Select
(
p
=>
Tuple
.
Create
(
p
.
GetSetMethod
(
true
),
p
.
PropertyType
.
GetConstructor
(
new
[]
{
typeof
(
TDatabase
),
typeof
(
string
)
}),
...
...
Dapper.Rainbow/Snapshotter.cs
浏览文件 @
8152f2c7
...
...
@@ -91,8 +91,8 @@ private static List<PropertyInfo> RelevantProperties()
p
.
GetSetMethod
(
true
)
!=
null
&&
p
.
GetGetMethod
(
true
)
!=
null
&&
(
p
.
PropertyType
==
typeof
(
string
)
||
p
.
PropertyType
.
IsValueType
()
||
(
p
.
PropertyType
.
IsGenericType
()
&&
p
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>)))
||
p
.
PropertyType
.
IsValueType
||
(
p
.
PropertyType
.
IsGenericType
&&
p
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>)))
).
ToList
();
}
...
...
@@ -109,13 +109,13 @@ private static bool AreEqual<U>(U first, U second)
var
il
=
dm
.
GetILGenerator
();
// change list
il
.
DeclareLocal
(
typeof
(
List
<
Change
>));
il
.
DeclareLocal
(
typeof
(
Change
));
il
.
DeclareLocal
(
typeof
(
object
));
// boxed change
var
list
=
il
.
DeclareLocal
(
typeof
(
List
<
Change
>));
var
change
=
il
.
DeclareLocal
(
typeof
(
Change
));
var
boxed
=
il
.
DeclareLocal
(
typeof
(
object
));
// boxed change
il
.
Emit
(
OpCodes
.
Newobj
,
typeof
(
List
<
Change
>).
GetConstructor
(
Type
.
EmptyTypes
));
// [list]
il
.
Emit
(
OpCodes
.
Stloc
_0
);
il
.
Emit
(
OpCodes
.
Stloc
,
list
);
foreach
(
var
prop
in
RelevantProperties
())
{
...
...
@@ -138,7 +138,7 @@ private static bool AreEqual<U>(U first, U second)
// [original prop val, current prop val, current prop val boxed]
}
il
.
Emit
(
OpCodes
.
Stloc
_2
);
il
.
Emit
(
OpCodes
.
Stloc
,
boxed
);
// [original prop val, current prop val]
il
.
EmitCall
(
OpCodes
.
Call
,
typeof
(
Snapshot
<
T
>).
GetMethod
(
nameof
(
AreEqual
),
BindingFlags
.
NonPublic
|
BindingFlags
.
Static
).
MakeGenericMethod
(
new
Type
[]
{
prop
.
PropertyType
}),
null
);
...
...
@@ -153,7 +153,7 @@ private static bool AreEqual<U>(U first, U second)
il
.
Emit
(
OpCodes
.
Dup
);
// [change,change]
il
.
Emit
(
OpCodes
.
Stloc
_1
);
il
.
Emit
(
OpCodes
.
Stloc
,
change
);
// [change]
il
.
Emit
(
OpCodes
.
Ldstr
,
prop
.
Name
);
...
...
@@ -161,18 +161,18 @@ private static bool AreEqual<U>(U first, U second)
il
.
Emit
(
OpCodes
.
Callvirt
,
typeof
(
Change
).
GetMethod
(
"set_Name"
));
// []
il
.
Emit
(
OpCodes
.
Ldloc
_1
);
il
.
Emit
(
OpCodes
.
Ldloc
,
change
);
// [change]
il
.
Emit
(
OpCodes
.
Ldloc
_2
);
il
.
Emit
(
OpCodes
.
Ldloc
,
boxed
);
// [change, boxed]
il
.
Emit
(
OpCodes
.
Callvirt
,
typeof
(
Change
).
GetMethod
(
"set_NewValue"
));
// []
il
.
Emit
(
OpCodes
.
Ldloc
_0
);
il
.
Emit
(
OpCodes
.
Ldloc
,
list
);
// [change list]
il
.
Emit
(
OpCodes
.
Ldloc
_1
);
il
.
Emit
(
OpCodes
.
Ldloc
,
change
);
// [change list, change]
il
.
Emit
(
OpCodes
.
Callvirt
,
typeof
(
List
<
Change
>).
GetMethod
(
"Add"
));
// []
...
...
@@ -180,7 +180,7 @@ private static bool AreEqual<U>(U first, U second)
il
.
MarkLabel
(
skip
);
}
il
.
Emit
(
OpCodes
.
Ldloc
_0
);
il
.
Emit
(
OpCodes
.
Ldloc
,
list
);
// [change list]
il
.
Emit
(
OpCodes
.
Ret
);
...
...
@@ -195,14 +195,14 @@ private static bool AreEqual<U>(U first, U second)
var
il
=
dm
.
GetILGenerator
();
il
.
DeclareLocal
(
typeof
(
T
));
var
typed
=
il
.
DeclareLocal
(
typeof
(
T
));
il
.
Emit
(
OpCodes
.
Newobj
,
ctor
);
il
.
Emit
(
OpCodes
.
Stloc
_0
);
il
.
Emit
(
OpCodes
.
Stloc
,
typed
);
foreach
(
var
prop
in
RelevantProperties
())
{
il
.
Emit
(
OpCodes
.
Ldloc
_0
);
il
.
Emit
(
OpCodes
.
Ldloc
,
typed
);
// [clone]
il
.
Emit
(
OpCodes
.
Ldarg_0
);
// [clone, source]
...
...
@@ -213,7 +213,7 @@ private static bool AreEqual<U>(U first, U second)
}
// Load new constructed obj on eval stack -> 1 item on stack
il
.
Emit
(
OpCodes
.
Ldloc
_0
);
il
.
Emit
(
OpCodes
.
Ldloc
,
typed
);
// Return constructed object. --> 0 items on stack
il
.
Emit
(
OpCodes
.
Ret
);
...
...
Dapper.SqlBuilder/Dapper.SqlBuilder.csproj
浏览文件 @
8152f2c7
...
...
@@ -5,21 +5,15 @@
<Title>Dapper SqlBuilder component</Title>
<Description>The Dapper SqlBuilder component, for building SQL queries dynamically.</Description>
<Authors>Sam Saffron, Johan Danforth</Authors>
<TargetFrameworks>net451;netstandard1.3</TargetFrameworks>
<!-- TODO: Docs -->
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup>
<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'">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
</ItemGroup>
</Project>
\ No newline at end of file
Dapper.StrongName/Dapper.StrongName.csproj
浏览文件 @
8152f2c7
...
...
@@ -5,37 +5,15 @@
<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>net
451;netstandard1.3;netstandard2.0;netcoreapp2.1
</TargetFrameworks>
<TargetFrameworks>net
standard2.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)' == 'net451'">
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' OR '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
<!-- it would be nice to use System.Data.Common here, but we need SqlClient for SqlDbType in 1.3, and legacy SqlDataRecord API-->
<!--<PackageReference Include="System.Data.Common" Version="4.3.0" />-->
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
</ItemGroup>
<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.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
</ItemGroup>
</Project>
Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj
浏览文件 @
8152f2c7
...
...
@@ -6,7 +6,7 @@
<DebugType>portable</DebugType>
<OutputType>Exe</OutputType>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFrameworks>netcoreapp
1.0;netcoreapp
2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Dapper.Tests\Helpers\XunitSkippable.cs;..\Dapper\TypeExtensions.cs" />
...
...
@@ -16,11 +16,15 @@
<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.1
" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="1
5.3
.0" />
<PackageReference Include="MySqlConnector" Version="0.
44.1
" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="
2.2.6
" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="1
6.2
.0" />
<PackageReference Include="MySqlConnector" Version="0.
56.0
" />
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
</ItemGroup>
<!-- note: define SQLCE if SQL CE is available -->
</Project>
Dapper.Tests.Contrib/TestSuite.cs
浏览文件 @
8152f2c7
...
...
@@ -2,14 +2,10 @@
using
System.Collections.Generic
;
using
System.Data
;
using
System.Linq
;
using
System.Transactions
;
using
Dapper.Contrib.Extensions
;
using
Xunit
;
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using
System.Transactions
;
using
System.Data.SqlServerCe
;
#endif
using
FactAttribute
=
Dapper
.
Tests
.
Contrib
.
SkippableFactAttribute
;
namespace
Dapper.Tests.Contrib
...
...
@@ -525,7 +521,7 @@ public void InsertGetUpdate()
}
}
#if
!NETCOREAPP1_0 && !NETCOREAPP2_0
#if
SQLCE
[
Fact
(
Skip
=
"Not parallel friendly - thinking about how to test this"
)]
public
void
InsertWithCustomDbType
()
{
...
...
@@ -563,7 +559,7 @@ public void InsertWithCustomTableNameMapper()
{
SqlMapperExtensions
.
TableNameMapper
=
type
=>
{
switch
(
type
.
Name
()
)
switch
(
type
.
Name
)
{
case
"Person"
:
return
"People"
;
...
...
@@ -573,7 +569,7 @@ public void InsertWithCustomTableNameMapper()
return
tableattr
.
Name
;
var
name
=
type
.
Name
+
"s"
;
if
(
type
.
IsInterface
()
&&
name
.
StartsWith
(
"I"
))
if
(
type
.
IsInterface
&&
name
.
StartsWith
(
"I"
))
return
name
.
Substring
(
1
);
return
name
;
}
...
...
@@ -652,8 +648,7 @@ public void Transactions()
Assert
.
Equal
(
car
.
Name
,
orgName
);
}
}
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
#if TRANSCOPE
[
Fact
]
public
void
TransactionScope
()
{
...
...
@@ -665,7 +660,7 @@ public void TransactionScope()
txscope
.
Dispose
();
//rollback
Assert
.
Is
Null
(
connection
.
Get
<
Car
>(
id
));
//returns null - car with that id should not exist
Assert
.
Null
(
connection
.
Get
<
Car
>(
id
));
//returns null - car with that id should not exist
}
}
}
...
...
Dapper.Tests.Contrib/TestSuites.cs
浏览文件 @
8152f2c7
...
...
@@ -7,10 +7,6 @@
using
Xunit
;
using
Xunit.Sdk
;
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using
System.Data.SqlServerCe
;
#endif
namespace
Dapper.Tests.Contrib
{
// The test suites here implement TestSuiteBase so that each provider runs
...
...
@@ -72,7 +68,7 @@ public class MySqlServerTestSuite : TestSuite
public
override
IDbConnection
GetConnection
()
{
if
(
_skip
)
throw
new
SkipTestException
(
"Skipping MySQL Tests - no server."
);
if
(
_skip
)
Skip
.
Inconclusive
(
"Skipping MySQL Tests - no server."
);
return
new
MySqlConnection
(
ConnectionString
);
}
...
...
@@ -148,7 +144,8 @@ static SQLiteTestSuite()
}
}
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
#if SQLCE
public
class
SqlCETestSuite
:
TestSuite
{
const
string
FileName
=
"Test.DB.sdf"
;
...
...
Dapper.Tests.Performance/Config.cs
浏览文件 @
8152f2c7
...
...
@@ -22,7 +22,7 @@ public Config()
Add
(
MarkdownExporter
.
GitHub
);
Add
(
HtmlExporter
.
Default
);
var
md
=
new
MemoryDiagnoser
()
;
var
md
=
MemoryDiagnoser
.
Default
;
Add
(
md
);
Add
(
new
ORMColum
());
Add
(
TargetMethodColumn
.
Method
);
...
...
@@ -30,8 +30,8 @@ public Config()
Add
(
StatisticColumn
.
Mean
);
//Add(StatisticColumn.StdDev);
//Add(StatisticColumn.Error);
Add
(
Baseline
ScaledColumn
.
Scaled
);
Add
(
md
.
GetColumnProvider
());
Add
(
Baseline
RatioColumn
.
RatioMean
);
//
Add(md.GetColumnProvider());
Add
(
Job
.
ShortRun
.
WithLaunchCount
(
1
)
...
...
@@ -39,8 +39,8 @@ public Config()
.
WithUnrollFactor
(
Iterations
)
.
WithIterationCount
(
1
)
);
Set
(
new
DefaultOrderer
(
SummaryOrderPolicy
.
FastestToSlowest
)
);
SummaryPerType
=
false
;
Orderer
=
new
DefaultOrderer
(
SummaryOrderPolicy
.
FastestToSlowest
);
Options
|=
ConfigOptions
.
JoinSummary
;
}
}
}
Dapper.Tests.Performance/Dapper.Tests.Performance.csproj
浏览文件 @
8152f2c7
...
...
@@ -12,27 +12,27 @@
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" />
<PackageReference Include="Dashing" Version="2.
0.7
" />
<PackageReference Include="Dashing.Weaver" Version="2.
0.7
" />
<PackageReference Include="Dashing" Version="2.
2.0
" />
<PackageReference Include="Dashing.Weaver" Version="2.
2.0
" />
<PackageReference Include="Belgrade.Sql.Client" Version="1.1.4" />
<PackageReference Include="BenchmarkDotNet" Version="0.11.
1
" />
<PackageReference Include="DevExpress.Xpo" Version="1
8.1.6
" />
<PackageReference Include="BenchmarkDotNet" Version="0.11.
5
" />
<PackageReference Include="DevExpress.Xpo" Version="1
9.1.5
" />
<!--<PackageReference Include="BLToolkit" Version="4.3.6" />-->
<PackageReference Include="EntityFramework" Version="6.2.0" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="
6.3
.0" />
<PackageReference Include="linq2db.SqlServer" Version="2.
3
.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.
1.2
" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.
314.76
" />
<PackageReference Include="MySqlConnector" Version="0.
44.1
" />
<PackageReference Include="NHibernate" Version="5.
1.3
" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="
7.0
.0" />
<PackageReference Include="linq2db.SqlServer" Version="2.
9
.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.
2.6
" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.
1016.290
" />
<PackageReference Include="MySqlConnector" Version="0.
56.0
" />
<PackageReference Include="NHibernate" Version="5.
2.5
" />
<PackageReference Include="Iesi.Collections" Version="4.0.4" />
<PackageReference Include="Npgsql" Version="4.0.
3
" />
<PackageReference Include="Npgsql" Version="4.0.
9
" />
<PackageReference Include="PetaPoco" Version="5.1.306" />
<PackageReference Include="ServiceStack.OrmLite.SqlServer.Signed" Version="4.5.14" />
<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.1
09.
1" />
<PackageReference Include="System.Data.SQLite" Version="1.0.1
1
1" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
...
...
Dapper.Tests.Performance/Helpers/ORMColum.cs
浏览文件 @
8152f2c7
...
...
@@ -19,7 +19,7 @@ public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
return
type
.
GetCustomAttribute
<
DescriptionAttribute
>()?.
Description
??
type
.
Name
.
Replace
(
"Benchmarks"
,
string
.
Empty
);
}
public
string
GetValue
(
Summary
summary
,
BenchmarkCase
benchmarkCase
,
I
SummaryStyle
style
)
=>
GetValue
(
summary
,
benchmarkCase
);
public
string
GetValue
(
Summary
summary
,
BenchmarkCase
benchmarkCase
,
SummaryStyle
style
)
=>
GetValue
(
summary
,
benchmarkCase
);
public
bool
IsAvailable
(
Summary
summary
)
=>
true
;
public
bool
AlwaysShow
=>
true
;
...
...
Dapper.Tests.Performance/Helpers/ReturnColum.cs
浏览文件 @
8152f2c7
...
...
@@ -17,7 +17,7 @@ public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
return
type
==
typeof
(
object
)
?
"dynamic"
:
type
.
Name
;
}
public
string
GetValue
(
Summary
summary
,
BenchmarkCase
benchmarkCase
,
I
SummaryStyle
style
)
=>
GetValue
(
summary
,
benchmarkCase
);
public
string
GetValue
(
Summary
summary
,
BenchmarkCase
benchmarkCase
,
SummaryStyle
style
)
=>
GetValue
(
summary
,
benchmarkCase
);
public
bool
IsAvailable
(
Summary
summary
)
=>
true
;
public
bool
AlwaysShow
=>
true
;
...
...
Dapper.Tests/App.config
0 → 100644
浏览文件 @
8152f2c7
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
configuration
>
<
runtime
>
<
assemblyBinding
xmlns
=
"urn:schemas-microsoft-com:asm.v1"
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Microsoft.SqlServer.Types"
publicKeyToken
=
"89845dcd8080cc91"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"10.0.0.0"
newVersion
=
"14.0.0.0"
/>
</
dependentAssembly
>
</
assemblyBinding
>
</
runtime
>
</
configuration
>
Dapper.Tests/AsyncTests.cs
浏览文件 @
8152f2c7
...
...
@@ -6,6 +6,7 @@
using
System.Threading
;
using
Xunit
;
using
System.Data.Common
;
using
Xunit.Abstractions
;
namespace
Dapper.Tests
{
...
...
@@ -17,10 +18,14 @@ public sealed class MicrosoftSqlClientAsyncTests : AsyncTests<MicrosoftSqlClient
#endif
[
Collection
(
NonParallelDefinition
.
Name
)]
public
sealed
class
SystemSqlClientAsyncQueryCacheTests
:
AsyncQueryCacheTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
SystemSqlClientAsyncQueryCacheTests
:
AsyncQueryCacheTests
<
SystemSqlClientProvider
>
{
public
SystemSqlClientAsyncQueryCacheTests
(
ITestOutputHelper
log
)
:
base
(
log
)
{
}
}
#if MSSQLCLIENT
[
Collection
(
NonParallelDefinition
.
Name
)]
public
sealed
class
MicrosoftSqlClientAsyncQueryCacheTests
:
AsyncQueryCacheTests
<
MicrosoftSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientAsyncQueryCacheTests
:
AsyncQueryCacheTests
<
MicrosoftSqlClientProvider
>
{
public
MicrosoftSqlClientAsyncQueryCacheTests
(
ITestOutputHelper
log
)
:
base
(
log
)
{
}
}
#endif
...
...
@@ -818,6 +823,8 @@ public async Task Issue563_QueryAsyncShouldThrowException()
[
Collection
(
NonParallelDefinition
.
Name
)]
public
abstract
class
AsyncQueryCacheTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
SqlServerDatabaseProvider
{
private
readonly
ITestOutputHelper
_log
;
public
AsyncQueryCacheTests
(
ITestOutputHelper
log
)
=>
_log
=
log
;
private
DbConnection
_marsConnection
;
private
DbConnection
MarsConnection
=>
_marsConnection
??
(
_marsConnection
=
Provider
.
GetOpenConnection
(
true
));
...
...
@@ -847,8 +854,10 @@ public void AssertNoCacheWorksForQueryMultiple()
d
=
multi
.
Read
<
int
>().
Single
();
}
int
after
=
SqlMapper
.
GetCachedSQLCount
();
Assert
.
Equal
(
0
,
before
);
Assert
.
Equal
(
0
,
after
);
_log
?.
WriteLine
(
$"before:
{
before
}
; after:
{
after
}
"
);
// too brittle in concurrent tests to assert
// Assert.Equal(0, before);
// Assert.Equal(0, after);
Assert
.
Equal
(
123
,
c
);
Assert
.
Equal
(
456
,
d
);
}
...
...
Dapper.Tests/ConstructorTests.cs
浏览文件 @
8152f2c7
...
...
@@ -5,8 +5,10 @@
namespace
Dapper.Tests
{
[
Collection
(
"ConstructorTests"
)]
public
sealed
class
SystemSqlClientConstructorTests
:
ConstructorTests
<
SystemSqlClientProvider
>
{
}
#if MSSQLCLIENT
[
Collection
(
"ConstructorTests"
)]
public
sealed
class
MicrosoftSqlClientConstructorTests
:
ConstructorTests
<
MicrosoftSqlClientProvider
>
{
}
#endif
...
...
Dapper.Tests/Dapper.Tests.csproj
浏览文件 @
8152f2c7
...
...
@@ -6,41 +6,60 @@
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<TargetFrameworks>netcoreapp2.1;net46
;netcoreapp2.0
;net472</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;net46
2
;net472</TargetFrameworks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net46' OR '$(TargetFramework)' == 'net472'">
<PropertyGroup Condition="'$(TargetFramework)' == 'net46
2
' OR '$(TargetFramework)' == 'net472'">
<DefineConstants>$(DefineConstants);ENTITY_FRAMEWORK;LINQ2SQL;OLEDB</DefineConstants>
</PropertyGroup>
<ItemGroup>
<None Remove="Test.DB.sdf" />
</ItemGroup>
<!-- these two go together
<PropertyGroup>
<DefineConstants>$(DefineConstants);MSSQLCLIENT</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.0.19128.1-Preview" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.0.19221.1-Preview" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.1016.290"
Condition="'$(TargetFramework)' == 'net462' OR '$(TargetFramework)' == 'net472'"/>
</ItemGroup>
<ItemGroup Condition="'$(Platform)'=='x64'">
<Content Include="$(USERPROFILE)\.nuget\packages\microsoft.sqlserver.types\14.0.1016.290\nativeBinaries\x64\*.dll"
Condition="'$(TargetFramework)' == 'net462' OR '$(TargetFramework)' == 'net472'">
<Link>%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup Condition="'$(Platform)'=='x86'">
<Content Include="$(USERPROFILE)\.nuget\packages\microsoft.sqlserver.types\14.0.1016.290\nativeBinaries\x86\*.dll"
Condition="'$(TargetFramework)' == 'net462' OR '$(TargetFramework)' == 'net472'">
<Link>%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
-->
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="
5.9.1
" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="1
5.3
.0" />
<PackageReference Include="MySqlConnector" Version="0.
44.1
" />
<PackageReference Include="Npgsql" Version="
3.2.5
" />
<PackageReference Include="System.ValueTuple" Version="4.
4
.0" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="
7.0.0
" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="1
6.2
.0" />
<PackageReference Include="MySqlConnector" Version="0.
56.0
" />
<PackageReference Include="Npgsql" Version="
4.0.9
" />
<PackageReference Include="System.ValueTuple" Version="4.
5
.0" />
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net46' OR '$(TargetFramework)' == 'net472'">
<ItemGroup Condition="'$(TargetFramework)' == 'net46
2
' OR '$(TargetFramework)' == 'net472'">
<ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.1" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.
314.76
" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.
1016.290
" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
...
...
@@ -50,23 +69,10 @@
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<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 Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.6" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.6" />
</ItemGroup>
<PropertyGroup>
<PostBuildEvent>
if not exist "$(TargetDir)x86" md "$(TargetDir)x86"
xcopy /s /y /q "$(NuGetPackageRoot)\Microsoft.SqlServer.Types\14.0.314.76\NativeBinaries\x86\*.*" "$(TargetDir)x86"
if not exist "$(TargetDir)x64" md "$(TargetDir)x64"
xcopy /s /y /q "$(NuGetPackageRoot)\Microsoft.SqlServer.Types\14.0.314.76\NativeBinaries\x64\*.*" "$(TargetDir)x64"
</PostBuildEvent>
</PropertyGroup>
</Project>
Dapper.Tests/DataReaderTests.cs
浏览文件 @
8152f2c7
...
...
@@ -4,8 +4,10 @@
namespace
Dapper.Tests
{
[
Collection
(
"DataReaderTests"
)]
public
sealed
class
SystemSqlClientDataReaderTests
:
DataReaderTests
<
SystemSqlClientProvider
>
{
}
#if MSSQLCLIENT
[
Collection
(
"DataReaderTests"
)]
public
sealed
class
MicrosoftSqlClientDataReaderTests
:
DataReaderTests
<
MicrosoftSqlClientProvider
>
{
}
#endif
...
...
Dapper.Tests/DecimalTests.cs
浏览文件 @
8152f2c7
...
...
@@ -5,8 +5,10 @@
namespace
Dapper.Tests
{
[
Collection
(
"DecimalTests"
)]
public
sealed
class
SystemSqlClientDecimalTests
:
DecimalTests
<
SystemSqlClientProvider
>
{
}
#if MSSQLCLIENT
[
Collection
(
"DecimalTests"
)]
public
sealed
class
MicrosoftSqlClientDecimalTests
:
DecimalTests
<
MicrosoftSqlClientProvider
>
{
}
#endif
public
abstract
class
DecimalTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
...
...
Dapper.Tests/EnumTests.cs
浏览文件 @
8152f2c7
...
...
@@ -4,8 +4,10 @@
namespace
Dapper.Tests
{
[
Collection
(
"EnumTests"
)]
public
sealed
class
SystemSqlClientEnumTests
:
EnumTests
<
SystemSqlClientProvider
>
{
}
#if MSSQLCLIENT
[
Collection
(
"EnumTests"
)]
public
sealed
class
MicrosoftSqlClientEnumTests
:
EnumTests
<
MicrosoftSqlClientProvider
>
{
}
#endif
public
abstract
class
EnumTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
...
...
Dapper.Tests/Helpers/Attributes.cs
浏览文件 @
8152f2c7
using
System
;
using
Xunit
;
using
Xunit
.Sdk
;
namespace
Dapper.Tests
{
/// <summary>
/// <para>Override for <see cref="Xunit.FactAttribute"/> that truncates our DisplayName down.</para>
/// <para>
/// Attribute that is applied to a method to indicate that it is a fact that should
/// be run by the test runner. It can also be extended to support a customized definition
/// of a test method.
/// </para>
/// </summary>
[
AttributeUsage
(
AttributeTargets
.
Method
,
AllowMultiple
=
false
)]
[
XunitTestCaseDiscoverer
(
"Dapper.Tests.FactDiscoverer"
,
"Dapper.Tests"
)]
public
class
FactAttribute
:
Xunit
.
FactAttribute
{
}
/// <summary>
/// <para>Override for <see cref="Xunit.TheoryAttribute"/> that truncates our DisplayName down.</para>
/// <para>
/// Marks a test method as being a data theory. Data theories are tests which are
/// fed various bits of data from a data source, mapping to parameters on the test
/// method. If the data source contains multiple rows, then the test method is executed
/// multiple times (once with each data row). Data is provided by attributes which
/// derive from Xunit.Sdk.DataAttribute (notably, Xunit.InlineDataAttribute and Xunit.MemberDataAttribute).
/// </para>
/// </summary>
[
AttributeUsage
(
AttributeTargets
.
Method
,
AllowMultiple
=
false
)]
[
XunitTestCaseDiscoverer
(
"Dapper.Tests.TheoryDiscoverer"
,
"Dapper.Tests"
)]
public
class
TheoryAttribute
:
Xunit
.
TheoryAttribute
{
}
[
AttributeUsage
(
AttributeTargets
.
Method
,
AllowMultiple
=
false
)]
public
sealed
class
FactLongRunningAttribute
:
FactAttribute
{
...
...
Dapper.Tests/Helpers/XunitSkippable.cs
浏览文件 @
8152f2c7
...
...
@@ -9,6 +9,17 @@
namespace
Dapper.Tests
{
public
static
class
Skip
{
public
static
void
Inconclusive
(
string
reason
=
"inconclusive"
)
=>
throw
new
SkipTestException
(
reason
);
public
static
void
If
<
T
>(
object
obj
,
string
reason
=
null
)
where
T
:
class
{
if
(
obj
is
T
)
Skip
.
Inconclusive
(
reason
??
$"not valid for
{
typeof
(
T
).
FullName
}
"
);
}
}
public
class
SkipTestException
:
Exception
{
public
SkipTestException
(
string
reason
)
:
base
(
reason
)
...
...
@@ -16,31 +27,40 @@ public SkipTestException(string reason) : base(reason)
}
}
// Most of the below is a direct copy & port from the wonderful examples by Brad Wilson at
// https://github.com/xunit/samples.xunit/tree/master/DynamicSkipExample
public
class
SkippableFactDiscoverer
:
IXunitTestCaseDiscoverer
public
class
FactDiscoverer
:
Xunit
.
Sdk
.
FactDiscoverer
{
p
rivate
readonly
IMessageSink
_diagnosticMessageSink
;
p
ublic
FactDiscoverer
(
IMessageSink
diagnosticMessageSink
)
:
base
(
diagnosticMessageSink
)
{
}
public
SkippableFactDiscoverer
(
IMessageSink
diagnosticMessageSink
)
{
_diagnosticMessageSink
=
diagnosticMessageSink
;
}
protected
override
IXunitTestCase
CreateTestCase
(
ITestFrameworkDiscoveryOptions
discoveryOptions
,
ITestMethod
testMethod
,
IAttributeInfo
factAttribute
)
=>
new
SkippableTestCase
(
DiagnosticMessageSink
,
discoveryOptions
.
MethodDisplayOrDefault
(),
discoveryOptions
.
MethodDisplayOptionsOrDefault
(),
testMethod
);
}
public
IEnumerable
<
IXunitTestCase
>
Discover
(
ITestFrameworkDiscoveryOptions
discoveryOptions
,
ITestMethod
testMethod
,
IAttributeInfo
factAttribute
)
{
yield
return
new
SkippableFactTestCase
(
_diagnosticMessageSink
,
discoveryOptions
.
MethodDisplayOrDefault
(),
discoveryOptions
.
MethodDisplayOptionsOrDefault
(),
testMethod
);
}
public
class
TheoryDiscoverer
:
Xunit
.
Sdk
.
TheoryDiscoverer
{
public
TheoryDiscoverer
(
IMessageSink
diagnosticMessageSink
)
:
base
(
diagnosticMessageSink
)
{
}
protected
override
IEnumerable
<
IXunitTestCase
>
CreateTestCasesForDataRow
(
ITestFrameworkDiscoveryOptions
discoveryOptions
,
ITestMethod
testMethod
,
IAttributeInfo
theoryAttribute
,
object
[]
dataRow
)
=>
new
[]
{
new
SkippableTestCase
(
DiagnosticMessageSink
,
discoveryOptions
.
MethodDisplayOrDefault
(),
discoveryOptions
.
MethodDisplayOptionsOrDefault
(),
testMethod
,
dataRow
)
};
protected
override
IEnumerable
<
IXunitTestCase
>
CreateTestCasesForSkip
(
ITestFrameworkDiscoveryOptions
discoveryOptions
,
ITestMethod
testMethod
,
IAttributeInfo
theoryAttribute
,
string
skipReason
)
=>
new
[]
{
new
SkippableTestCase
(
DiagnosticMessageSink
,
discoveryOptions
.
MethodDisplayOrDefault
(),
discoveryOptions
.
MethodDisplayOptionsOrDefault
(),
testMethod
)
};
protected
override
IEnumerable
<
IXunitTestCase
>
CreateTestCasesForTheory
(
ITestFrameworkDiscoveryOptions
discoveryOptions
,
ITestMethod
testMethod
,
IAttributeInfo
theoryAttribute
)
=>
new
[]
{
new
SkippableTheoryTestCase
(
DiagnosticMessageSink
,
discoveryOptions
.
MethodDisplayOrDefault
(),
discoveryOptions
.
MethodDisplayOptionsOrDefault
(),
testMethod
)
};
protected
override
IEnumerable
<
IXunitTestCase
>
CreateTestCasesForSkippedDataRow
(
ITestFrameworkDiscoveryOptions
discoveryOptions
,
ITestMethod
testMethod
,
IAttributeInfo
theoryAttribute
,
object
[]
dataRow
,
string
skipReason
)
=>
new
[]
{
new
NamedSkippedDataRowTestCase
(
DiagnosticMessageSink
,
discoveryOptions
.
MethodDisplayOrDefault
(),
discoveryOptions
.
MethodDisplayOptionsOrDefault
(),
testMethod
,
skipReason
,
dataRow
)
};
}
public
class
Skippable
Fact
TestCase
:
XunitTestCase
public
class
SkippableTestCase
:
XunitTestCase
{
protected
override
string
GetDisplayName
(
IAttributeInfo
factAttribute
,
string
displayName
)
=>
base
.
GetDisplayName
(
factAttribute
,
displayName
).
StripName
();
[
Obsolete
(
"Called by the de-serializer; should only be called by deriving classes for de-serialization purposes"
)]
public
SkippableFactTestCase
()
{
}
public
SkippableTestCase
()
{
}
public
Skippable
Fact
TestCase
(
IMessageSink
diagnosticMessageSink
,
TestMethodDisplay
defaultMethodDisplay
,
TestMethodDisplayOptions
defaultMethodDisplayOptions
,
ITestMethod
testMethod
,
object
[]
testMethodArguments
=
null
)
public
SkippableTestCase
(
IMessageSink
diagnosticMessageSink
,
TestMethodDisplay
defaultMethodDisplay
,
TestMethodDisplayOptions
defaultMethodDisplayOptions
,
ITestMethod
testMethod
,
object
[]
testMethodArguments
=
null
)
:
base
(
diagnosticMessageSink
,
defaultMethodDisplay
,
defaultMethodDisplayOptions
,
testMethod
,
testMethodArguments
)
{
}
...
...
@@ -52,36 +72,56 @@ public SkippableFactTestCase(IMessageSink diagnosticMessageSink, TestMethodDispl
ExceptionAggregator
aggregator
,
CancellationTokenSource
cancellationTokenSource
)
{
var
skipMessageBus
=
new
SkippableFactMessageBus
(
messageBus
);
var
result
=
await
base
.
RunAsync
(
diagnosticMessageSink
,
skipMessageBus
,
constructorArguments
,
aggregator
,
cancellationTokenSource
).
ConfigureAwait
(
false
);
if
(
skipMessageBus
.
DynamicallySkippedTestCount
>
0
)
{
result
.
Failed
-=
skipMessageBus
.
DynamicallySkippedTestCount
;
result
.
Skipped
+=
skipMessageBus
.
DynamicallySkippedTestCount
;
}
return
result
;
var
skipMessageBus
=
new
SkippableMessageBus
(
messageBus
);
var
result
=
await
base
.
RunAsync
(
diagnosticMessageSink
,
skipMessageBus
,
constructorArguments
,
aggregator
,
cancellationTokenSource
).
ConfigureAwait
(
false
);
return
result
.
Update
(
skipMessageBus
);
}
}
public
class
Skippable
FactMessageBus
:
IMessageBus
public
class
Skippable
TheoryTestCase
:
XunitTheoryTestCase
{
private
readonly
IMessageBus
_innerBus
;
public
SkippableFactMessageBus
(
IMessageBus
innerBus
)
protected
override
string
GetDisplayName
(
IAttributeInfo
factAttribute
,
string
displayName
)
=>
base
.
GetDisplayName
(
factAttribute
,
displayName
).
StripName
();
[
Obsolete
(
"Called by the de-serializer; should only be called by deriving classes for de-serialization purposes"
)]
public
SkippableTheoryTestCase
()
{
}
public
SkippableTheoryTestCase
(
IMessageSink
diagnosticMessageSink
,
TestMethodDisplay
defaultMethodDisplay
,
TestMethodDisplayOptions
defaultMethodDisplayOptions
,
ITestMethod
testMethod
)
:
base
(
diagnosticMessageSink
,
defaultMethodDisplay
,
defaultMethodDisplayOptions
,
testMethod
)
{
}
public
override
async
Task
<
RunSummary
>
RunAsync
(
IMessageSink
diagnosticMessageSink
,
IMessageBus
messageBus
,
object
[]
constructorArguments
,
ExceptionAggregator
aggregator
,
CancellationTokenSource
cancellationTokenSource
)
{
_innerBus
=
innerBus
;
var
skipMessageBus
=
new
SkippableMessageBus
(
messageBus
);
var
result
=
await
base
.
RunAsync
(
diagnosticMessageSink
,
skipMessageBus
,
constructorArguments
,
aggregator
,
cancellationTokenSource
).
ConfigureAwait
(
false
);
return
result
.
Update
(
skipMessageBus
);
}
}
public
class
NamedSkippedDataRowTestCase
:
XunitSkippedDataRowTestCase
{
protected
override
string
GetDisplayName
(
IAttributeInfo
factAttribute
,
string
displayName
)
=>
base
.
GetDisplayName
(
factAttribute
,
displayName
).
StripName
();
[
Obsolete
(
"Called by the de-serializer; should only be called by deriving classes for de-serialization purposes"
)]
public
NamedSkippedDataRowTestCase
()
{
}
public
NamedSkippedDataRowTestCase
(
IMessageSink
diagnosticMessageSink
,
TestMethodDisplay
defaultMethodDisplay
,
TestMethodDisplayOptions
defaultMethodDisplayOptions
,
ITestMethod
testMethod
,
string
skipReason
,
object
[]
testMethodArguments
=
null
)
:
base
(
diagnosticMessageSink
,
defaultMethodDisplay
,
defaultMethodDisplayOptions
,
testMethod
,
skipReason
,
testMethodArguments
)
{
}
}
public
class
SkippableMessageBus
:
IMessageBus
{
private
readonly
IMessageBus
InnerBus
;
public
SkippableMessageBus
(
IMessageBus
innerBus
)
=>
InnerBus
=
innerBus
;
public
int
DynamicallySkippedTestCount
{
get
;
private
set
;
}
public
void
Dispose
()
{
}
public
void
Dispose
()
{
}
public
bool
QueueMessage
(
IMessageSinkMessage
message
)
{
...
...
@@ -91,10 +131,26 @@ public bool QueueMessage(IMessageSinkMessage message)
if
(
exceptionType
==
typeof
(
SkipTestException
).
FullName
)
{
DynamicallySkippedTestCount
++;
return
_i
nnerBus
.
QueueMessage
(
new
TestSkipped
(
testFailed
.
Test
,
testFailed
.
Messages
.
FirstOrDefault
()));
return
I
nnerBus
.
QueueMessage
(
new
TestSkipped
(
testFailed
.
Test
,
testFailed
.
Messages
.
FirstOrDefault
()));
}
}
return
_innerBus
.
QueueMessage
(
message
);
return
InnerBus
.
QueueMessage
(
message
);
}
}
internal
static
class
XUnitExtensions
{
internal
static
string
StripName
(
this
string
name
)
=>
name
.
Replace
(
"Dapper.Tests."
,
""
);
public
static
RunSummary
Update
(
this
RunSummary
summary
,
SkippableMessageBus
bus
)
{
if
(
bus
.
DynamicallySkippedTestCount
>
0
)
{
summary
.
Failed
-=
bus
.
DynamicallySkippedTestCount
;
summary
.
Skipped
+=
bus
.
DynamicallySkippedTestCount
;
}
return
summary
;
}
}
}
Dapper.Tests/LiteralTests.cs
浏览文件 @
8152f2c7
...
...
@@ -3,8 +3,10 @@
namespace
Dapper.Tests
{
[
Collection
(
"LiteralTests"
)]
public
sealed
class
SystemSqlClientLiteralTests
:
LiteralTests
<
SystemSqlClientProvider
>
{
}
#if MSSQLCLIENT
[
Collection
(
"LiteralTests"
)]
public
sealed
class
MicrosoftSqlClientLiteralTests
:
LiteralTests
<
MicrosoftSqlClientProvider
>
{
}
#endif
public
abstract
class
LiteralTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
...
...
Dapper.Tests/MiscTests.cs
浏览文件 @
8152f2c7
...
...
@@ -39,8 +39,10 @@ public GenericUriParser(GenericUriParserOptions options)
namespace
Dapper.Tests
{
[
Collection
(
"MiscTests"
)]
public
sealed
class
SystemSqlClientMiscTests
:
MiscTests
<
SystemSqlClientProvider
>
{
}
#if MSSQLCLIENT
[
Collection
(
"MiscTests"
)]
public
sealed
class
MicrosoftSqlClientMiscTests
:
MiscTests
<
MicrosoftSqlClientProvider
>
{
}
#endif
public
abstract
class
MiscTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
...
...
Dapper.Tests/MultiMapTests.cs
浏览文件 @
8152f2c7
...
...
@@ -6,8 +6,10 @@
namespace
Dapper.Tests
{
[
Collection
(
"MultiMapTests"
)]
public
sealed
class
SystemSqlClientMultiMapTests
:
MultiMapTests
<
SystemSqlClientProvider
>
{
}
#if MSSQLCLIENT
[
Collection
(
"MultiMapTests"
)]
public
sealed
class
MicrosoftSqlClientMultiMapTests
:
MultiMapTests
<
MicrosoftSqlClientProvider
>
{
}
#endif
public
abstract
class
MultiMapTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
...
...
Dapper.Tests/ParameterTests.cs
浏览文件 @
8152f2c7
...
...
@@ -43,7 +43,19 @@ void SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, SqlMapper.Id
}
}
private
static
List
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
CreateSqlDataRecordList
(
IEnumerable
<
int
>
numbers
)
private
static
IEnumerable
<
IDataRecord
>
CreateSqlDataRecordList
(
IDbCommand
command
,
IEnumerable
<
int
>
numbers
)
{
if
(
command
is
System
.
Data
.
SqlClient
.
SqlCommand
)
return
CreateSqlDataRecordList_SD
(
numbers
);
if
(
command
is
Microsoft
.
Data
.
SqlClient
.
SqlCommand
)
return
CreateSqlDataRecordList_MD
(
numbers
);
throw
new
ArgumentException
(
nameof
(
command
));
}
private
static
IEnumerable
<
IDataRecord
>
CreateSqlDataRecordList
(
IDbConnection
connection
,
IEnumerable
<
int
>
numbers
)
{
if
(
connection
is
System
.
Data
.
SqlClient
.
SqlConnection
)
return
CreateSqlDataRecordList_SD
(
numbers
);
if
(
connection
is
Microsoft
.
Data
.
SqlClient
.
SqlConnection
)
return
CreateSqlDataRecordList_MD
(
numbers
);
throw
new
ArgumentException
(
nameof
(
connection
));
}
private
static
List
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
CreateSqlDataRecordList_SD
(
IEnumerable
<
int
>
numbers
)
{
var
number_list
=
new
List
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>();
...
...
@@ -60,7 +72,25 @@ private static List<Microsoft.SqlServer.Server.SqlDataRecord> CreateSqlDataRecor
return
number_list
;
}
private
static
List
<
Microsoft
.
Data
.
SqlClient
.
Server
.
SqlDataRecord
>
CreateSqlDataRecordList_MD
(
IEnumerable
<
int
>
numbers
)
{
var
number_list
=
new
List
<
Microsoft
.
Data
.
SqlClient
.
Server
.
SqlDataRecord
>();
// Create an SqlMetaData object that describes our table type.
Microsoft
.
Data
.
SqlClient
.
Server
.
SqlMetaData
[]
tvp_definition
=
{
new
Microsoft
.
Data
.
SqlClient
.
Server
.
SqlMetaData
(
"n"
,
SqlDbType
.
Int
)
};
foreach
(
int
n
in
numbers
)
{
// Create a new record, using the metadata array above.
var
rec
=
new
Microsoft
.
Data
.
SqlClient
.
Server
.
SqlDataRecord
(
tvp_definition
);
rec
.
SetInt32
(
0
,
n
);
// Set the value.
number_list
.
Add
(
rec
);
// Add it to the list.
}
return
number_list
;
}
private
class
IntDynamicParam
:
SqlMapper
.
IDynamicParameters
{
...
...
@@ -72,16 +102,11 @@ public IntDynamicParam(IEnumerable<int> numbers)
public
void
AddParameters
(
IDbCommand
command
,
SqlMapper
.
Identity
identity
)
{
var
sqlCommand
=
(
System
.
Data
.
SqlClient
.
SqlCommand
)
command
;
sqlCommand
.
CommandType
=
CommandType
.
StoredProcedure
;
command
.
CommandType
=
CommandType
.
StoredProcedure
;
var
number_list
=
CreateSqlDataRecordList
(
numbers
);
var
number_list
=
CreateSqlDataRecordList
(
command
,
numbers
);
// Add the table parameter.
var
p
=
sqlCommand
.
Parameters
.
Add
(
"ints"
,
SqlDbType
.
Structured
);
p
.
Direction
=
ParameterDirection
.
Input
;
p
.
TypeName
=
"int_list_type"
;
p
.
Value
=
number_list
;
AddStructured
(
command
,
number_list
);
}
}
...
...
@@ -95,17 +120,35 @@ public IntCustomParam(IEnumerable<int> numbers)
public
void
AddParameter
(
IDbCommand
command
,
string
name
)
{
var
sqlCommand
=
(
System
.
Data
.
SqlClient
.
SqlCommand
)
command
;
sqlCommand
.
CommandType
=
CommandType
.
StoredProcedure
;
command
.
CommandType
=
CommandType
.
StoredProcedure
;
var
number_list
=
CreateSqlDataRecordList
(
numbers
);
var
number_list
=
CreateSqlDataRecordList
(
command
,
numbers
);
// Add the table parameter.
var
p
=
sqlCommand
.
Parameters
.
Add
(
name
,
SqlDbType
.
Structured
);
AddStructured
(
command
,
number_list
);
}
}
private
static
IDbDataParameter
AddStructured
(
IDbCommand
command
,
object
value
)
{
if
(
command
is
System
.
Data
.
SqlClient
.
SqlCommand
sdcmd
)
{
var
p
=
sdcmd
.
Parameters
.
Add
(
"integers"
,
SqlDbType
.
Structured
);
p
.
Direction
=
ParameterDirection
.
Input
;
p
.
TypeName
=
"int_list_type"
;
p
.
Value
=
number_list
;
p
.
Value
=
value
;
return
p
;
}
else
if
(
command
is
Microsoft
.
Data
.
SqlClient
.
SqlCommand
mdcmd
)
{
var
p
=
mdcmd
.
Parameters
.
Add
(
"integers"
,
SqlDbType
.
Structured
);
p
.
Direction
=
ParameterDirection
.
Input
;
p
.
TypeName
=
"int_list_type"
;
p
.
Value
=
value
;
return
p
;
}
else
throw
new
ArgumentException
(
nameof
(
command
));
}
/* TODO:
...
...
@@ -286,7 +329,7 @@ public void TestTVP()
try
{
connection
.
Execute
(
"CREATE TYPE int_list_type AS TABLE (n int NOT NULL PRIMARY KEY)"
);
connection
.
Execute
(
"CREATE PROC get_ints @int
s int_list_type READONLY AS select * from @int
s"
);
connection
.
Execute
(
"CREATE PROC get_ints @int
egers int_list_type READONLY AS select * from @integer
s"
);
var
nums
=
connection
.
Query
<
int
>(
"get_ints"
,
new
IntDynamicParam
(
new
int
[]
{
1
,
2
,
3
})).
ToList
();
Assert
.
Equal
(
1
,
nums
[
0
]);
...
...
@@ -298,11 +341,11 @@ public void TestTVP()
{
try
{
connection
.
Execute
(
"DROP PROC get_ints"
);
try
{
connection
.
Execute
(
"DROP PROC get_ints"
);
}
catch
{
}
}
finally
{
connection
.
Execute
(
"DROP TYPE int_list_type"
);
try
{
connection
.
Execute
(
"DROP TYPE int_list_type"
);
}
catch
{
}
}
}
}
...
...
@@ -319,16 +362,12 @@ public new void AddParameters(IDbCommand command, SqlMapper.Identity identity)
{
base
.
AddParameters
(
command
,
identity
);
var
sqlCommand
=
(
System
.
Data
.
SqlClient
.
SqlCommand
)
command
;
sqlCommand
.
CommandType
=
CommandType
.
StoredProcedure
;
command
.
CommandType
=
CommandType
.
StoredProcedure
;
var
number_list
=
CreateSqlDataRecordList
(
numbers
);
var
number_list
=
CreateSqlDataRecordList
(
command
,
numbers
);
// Add the table parameter.
var
p
=
sqlCommand
.
Parameters
.
Add
(
"ints"
,
SqlDbType
.
Structured
);
p
.
Direction
=
ParameterDirection
.
Input
;
p
.
TypeName
=
"int_list_type"
;
p
.
Value
=
number_list
;
AddStructured
(
command
,
number_list
);
}
}
...
...
@@ -338,7 +377,7 @@ public void TestTVPWithAdditionalParams()
try
{
connection
.
Execute
(
"CREATE TYPE int_list_type AS TABLE (n int NOT NULL PRIMARY KEY)"
);
connection
.
Execute
(
"CREATE PROC get_values @int
s int_list_type READONLY, @stringParam varchar(20), @dateParam datetime AS select i.*, @stringParam as stringParam, @dateParam as dateParam from @int
s i"
);
connection
.
Execute
(
"CREATE PROC get_values @int
egers int_list_type READONLY, @stringParam varchar(20), @dateParam datetime AS select i.*, @stringParam as stringParam, @dateParam as dateParam from @integer
s i"
);
var
dynamicParameters
=
new
DynamicParameterWithIntTVP
(
new
int
[]
{
1
,
2
,
3
});
dynamicParameters
.
AddDynamicParams
(
new
{
stringParam
=
"stringParam"
,
dateParam
=
new
DateTime
(
2012
,
1
,
1
)
});
...
...
@@ -374,7 +413,7 @@ public void TestSqlDataRecordListParametersWithAsTableValuedParameter()
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
records
=
CreateSqlDataRecordList
(
connection
,
new
int
[]
{
1
,
2
,
3
});
var
nums
=
connection
.
Query
<
int
>(
"get_ints"
,
new
{
integers
=
records
.
AsTableValuedParameter
()
},
commandType
:
CommandType
.
StoredProcedure
).
ToList
();
Assert
.
Equal
(
new
int
[]
{
1
,
2
,
3
},
nums
);
...
...
@@ -414,7 +453,7 @@ public void TestEmptySqlDataRecordListParametersWithAsTableValuedParameter()
connection
.
Execute
(
"CREATE PROC get_ints @integers int_list_type READONLY AS select * from @integers"
);
var
emptyRecord
=
CreateSqlDataRecordList
(
Enumerable
.
Empty
<
int
>());
var
emptyRecord
=
CreateSqlDataRecordList
(
connection
,
Enumerable
.
Empty
<
int
>());
var
nums
=
connection
.
Query
<
int
>(
"get_ints"
,
new
{
integers
=
emptyRecord
.
AsTableValuedParameter
()
},
commandType
:
CommandType
.
StoredProcedure
).
ToList
();
Assert
.
True
(
nums
.
Count
==
0
);
...
...
@@ -441,14 +480,28 @@ public void TestSqlDataRecordListParametersWithTypeHandlers()
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
});
object
args
;
if
(
connection
is
System
.
Data
.
SqlClient
.
SqlConnection
)
{
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
records
=
CreateSqlDataRecordList_SD
(
new
int
[]
{
1
,
2
,
3
});
args
=
new
{
integers
=
records
};
}
else
if
(
connection
is
Microsoft
.
Data
.
SqlClient
.
SqlConnection
)
{
IEnumerable
<
Microsoft
.
Data
.
SqlClient
.
Server
.
SqlDataRecord
>
records
=
CreateSqlDataRecordList_MD
(
new
int
[]
{
1
,
2
,
3
});
args
=
new
{
integers
=
records
};
}
else
{
throw
new
ArgumentException
(
nameof
(
connection
));
}
var
nums
=
connection
.
Query
<
int
>(
"get_ints"
,
new
{
integers
=
records
}
,
commandType
:
CommandType
.
StoredProcedure
).
ToList
();
var
nums
=
connection
.
Query
<
int
>(
"get_ints"
,
args
,
commandType
:
CommandType
.
StoredProcedure
).
ToList
();
Assert
.
Equal
(
new
int
[]
{
1
,
2
,
3
},
nums
);
try
{
connection
.
Query
<
int
>(
"select * from @integers"
,
new
{
integers
=
records
}
).
First
();
connection
.
Query
<
int
>(
"select * from @integers"
,
args
).
First
();
throw
new
InvalidOperationException
();
}
catch
(
Exception
ex
)
...
...
@@ -665,6 +718,8 @@ private class HazSqlGeo
[
Fact
]
public
void
DBGeography_SO24405645_SO24402424
()
{
SkipIfMsDataClient
();
EntityFramework
.
Handlers
.
Register
();
connection
.
Execute
(
"create table #Geo (id int, geo geography, geometry geometry)"
);
...
...
@@ -686,6 +741,8 @@ public void DBGeography_SO24405645_SO24402424()
[
Fact
]
public
void
SqlGeography_SO25538154
()
{
SkipIfMsDataClient
();
SqlMapper
.
ResetTypeHandlers
();
connection
.
Execute
(
"create table #SqlGeo (id int, geo geography, geometry geometry)"
);
...
...
@@ -724,6 +781,8 @@ public void NullableSqlGeometry()
[
Fact
]
public
void
SqlHierarchyId_SO18888911
()
{
SkipIfMsDataClient
();
SqlMapper
.
ResetTypeHandlers
();
var
row
=
connection
.
Query
<
HazSqlHierarchy
>(
"select 3 as [Id], hierarchyid::Parse('/1/2/3/') as [Path]"
).
Single
();
Assert
.
Equal
(
3
,
row
.
Id
);
...
...
Dapper.Tests/ProcedureTests.cs
浏览文件 @
8152f2c7
...
...
@@ -6,8 +6,10 @@
namespace
Dapper.Tests
{
[
Collection
(
"ProcedureTests"
)]
public
sealed
class
SystemSqlClientProcedureTests
:
ProcedureTests
<
SystemSqlClientProvider
>
{
}
#if MSSQLCLIENT
[
Collection
(
"ProcedureTests"
)]
public
sealed
class
MicrosoftSqlClientProcedureTests
:
ProcedureTests
<
MicrosoftSqlClientProvider
>
{
}
#endif
public
abstract
class
ProcedureTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
...
...
Dapper.Tests/Providers/EntityFrameworkTests.cs
浏览文件 @
8152f2c7
...
...
@@ -22,6 +22,8 @@ public EntityFrameworkTests()
[
Fact
]
public
void
Issue570_DbGeo_HasValues
()
{
SkipIfMsDataClient
();
EntityFramework
.
Handlers
.
Register
();
const
string
redmond
=
"POINT (-122.1215 47.6740)"
;
DbGeography
point
=
DbGeography
.
PointFromText
(
redmond
,
DbGeography
.
DefaultCoordinateSystemId
);
...
...
@@ -37,6 +39,8 @@ public void Issue570_DbGeo_HasValues()
[
Fact
]
public
void
Issue22_ExecuteScalar_EntityFramework
()
{
SkipIfMsDataClient
();
var
geo
=
DbGeography
.
LineFromText
(
"LINESTRING(-122.360 47.656, -122.343 47.656 )"
,
4326
);
var
geo2
=
connection
.
ExecuteScalar
<
DbGeography
>(
"select @geo"
,
new
{
geo
});
Assert
.
NotNull
(
geo2
);
...
...
Dapper.Tests/QueryMultipleTests.cs
浏览文件 @
8152f2c7
...
...
@@ -6,8 +6,10 @@
namespace
Dapper.Tests
{
[
Collection
(
"QueryMultipleTests"
)]
public
sealed
class
SystemSqlClientQueryMultipleTests
:
QueryMultipleTests
<
SystemSqlClientProvider
>
{
}
#if MSSQLCLIENT
[
Collection
(
"QueryMultipleTests"
)]
public
sealed
class
MicrosoftSqlClientQueryMultipleTests
:
QueryMultipleTests
<
MicrosoftSqlClientProvider
>
{
}
#endif
public
abstract
class
QueryMultipleTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
...
...
Dapper.Tests/TestBase.cs
浏览文件 @
8152f2c7
...
...
@@ -81,6 +81,9 @@ public sealed class MicrosoftSqlClientProvider : SqlServerDatabaseProvider
public
abstract
class
TestBase
<
TProvider
>
:
IDisposable
where
TProvider
:
DatabaseProvider
{
protected
void
SkipIfMsDataClient
()
=>
Skip
.
If
<
Microsoft
.
Data
.
SqlClient
.
SqlConnection
>(
connection
);
protected
DbConnection
GetOpenConnection
()
=>
Provider
.
GetOpenConnection
();
protected
DbConnection
GetClosedConnection
()
=>
Provider
.
GetClosedConnection
();
protected
DbConnection
_connection
;
...
...
Dapper.Tests/TransactionTests.cs
浏览文件 @
8152f2c7
...
...
@@ -7,8 +7,10 @@
namespace
Dapper.Tests
{
[
Collection
(
"TransactionTests"
)]
public
sealed
class
SystemSqlClientTransactionTests
:
TransactionTests
<
SystemSqlClientProvider
>
{
}
#if MSSQLCLIENT
[
Collection
(
"TransactionTests"
)]
public
sealed
class
MicrosoftSqlClientTransactionTests
:
TransactionTests
<
MicrosoftSqlClientProvider
>
{
}
#endif
public
abstract
class
TransactionTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
...
...
Dapper.Tests/TupleTests.cs
浏览文件 @
8152f2c7
...
...
@@ -3,8 +3,10 @@
namespace
Dapper.Tests
{
[
Collection
(
"TupleTests"
)]
public
sealed
class
SystemSqlClientTupleTests
:
TupleTests
<
SystemSqlClientProvider
>
{
}
#if MSSQLCLIENT
[
Collection
(
"TupleTests"
)]
public
sealed
class
MicrosoftSqlClientTupleTests
:
TupleTests
<
MicrosoftSqlClientProvider
>
{
}
#endif
public
abstract
class
TupleTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
...
...
Dapper.Tests/XmlTests.cs
浏览文件 @
8152f2c7
...
...
@@ -4,8 +4,10 @@
namespace
Dapper.Tests
{
[
Collection
(
"XmlTests"
)]
public
sealed
class
SystemSqlClientXmlTests
:
XmlTests
<
SystemSqlClientProvider
>
{
}
#if MSSQLCLIENT
[
Collection
(
"XmlTests"
)]
public
sealed
class
MicrosoftSqlClientXmlTests
:
XmlTests
<
MicrosoftSqlClientProvider
>
{
}
#endif
public
abstract
class
XmlTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
...
...
Dapper.sln
浏览文件 @
8152f2c7
...
...
@@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
appveyor.yml = appveyor.yml
build.ps1 = build.ps1
Directory.build.props = Directory.build.props
global.json = global.json
docs\index.md = docs\index.md
License.txt = License.txt
nuget.config = nuget.config
...
...
Dapper/Dapper.csproj
浏览文件 @
8152f2c7
...
...
@@ -5,32 +5,10 @@
<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>net
451;netstandard1.3;netstandard2.0;netcoreapp2.1
</TargetFrameworks>
<TargetFrameworks>net
standard2.0
</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' OR '$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
<!-- it would be nice to use System.Data.Common here, but we need SqlClient for SqlDbType in 1.3, and legacy SqlDataRecord API-->
<!--<PackageReference Include="System.Data.Common" Version="4.3.0" />-->
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
</ItemGroup>
<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.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
</ItemGroup>
</Project>
Dapper/DataTableHandler.cs
浏览文件 @
8152f2c7
using
System
;
using
System.Data
;
#if !NETSTANDARD1_3
namespace
Dapper
{
internal
sealed
class
DataTableHandler
:
SqlMapper
.
ITypeHandler
...
...
@@ -16,4 +15,3 @@ public void SetValue(IDbDataParameter parameter, object value)
}
}
}
#
endif
\ No newline at end of file
Dapper/DefaultTypeMap.cs
浏览文件 @
8152f2c7
...
...
@@ -26,27 +26,11 @@ public DefaultTypeMap(Type type)
Properties
=
GetSettableProps
(
type
);
_type
=
type
;
}
#if NETSTANDARD1_3
private
static
bool
IsParameterMatch
(
ParameterInfo
[]
x
,
ParameterInfo
[]
y
)
{
if
(
ReferenceEquals
(
x
,
y
))
return
true
;
if
(
x
==
null
||
y
==
null
)
return
false
;
if
(
x
.
Length
!=
y
.
Length
)
return
false
;
for
(
int
i
=
0
;
i
<
x
.
Length
;
i
++)
if
(
x
[
i
].
ParameterType
!=
y
[
i
].
ParameterType
)
return
false
;
return
true
;
}
#endif
internal
static
MethodInfo
GetPropertySetter
(
PropertyInfo
propertyInfo
,
Type
type
)
{
if
(
propertyInfo
.
DeclaringType
==
type
)
return
propertyInfo
.
GetSetMethod
(
true
);
#if NETSTANDARD1_3
return
propertyInfo
.
DeclaringType
.
GetProperties
(
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
)
.
Single
(
x
=>
x
.
Name
==
propertyInfo
.
Name
&&
x
.
PropertyType
==
propertyInfo
.
PropertyType
&&
IsParameterMatch
(
x
.
GetIndexParameters
(),
propertyInfo
.
GetIndexParameters
())
).
GetSetMethod
(
true
);
#else
return
propertyInfo
.
DeclaringType
.
GetProperty
(
propertyInfo
.
Name
,
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
,
...
...
@@ -54,7 +38,6 @@ internal static MethodInfo GetPropertySetter(PropertyInfo propertyInfo, Type typ
propertyInfo
.
PropertyType
,
propertyInfo
.
GetIndexParameters
().
Select
(
p
=>
p
.
ParameterType
).
ToArray
(),
null
).
GetSetMethod
(
true
);
#endif
}
internal
static
List
<
PropertyInfo
>
GetSettableProps
(
Type
t
)
...
...
@@ -97,9 +80,9 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
continue
;
var
unboxedType
=
Nullable
.
GetUnderlyingType
(
ctorParameters
[
i
].
ParameterType
)
??
ctorParameters
[
i
].
ParameterType
;
if
((
unboxedType
!=
types
[
i
]
&&
!
SqlMapper
.
HasTypeHandler
(
unboxedType
))
&&
!(
unboxedType
.
IsEnum
()
&&
Enum
.
GetUnderlyingType
(
unboxedType
)
==
types
[
i
])
&&
!(
unboxedType
.
IsEnum
&&
Enum
.
GetUnderlyingType
(
unboxedType
)
==
types
[
i
])
&&
!(
unboxedType
==
typeof
(
char
)
&&
types
[
i
]
==
typeof
(
string
))
&&
!(
unboxedType
.
IsEnum
()
&&
types
[
i
]
==
typeof
(
string
)))
&&
!(
unboxedType
.
IsEnum
&&
types
[
i
]
==
typeof
(
string
)))
{
break
;
}
...
...
@@ -118,11 +101,7 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
public
ConstructorInfo
FindExplicitConstructor
()
{
var
constructors
=
_type
.
GetConstructors
(
BindingFlags
.
Instance
|
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
);
#if NETSTANDARD1_3
var
withAttr
=
constructors
.
Where
(
c
=>
c
.
CustomAttributes
.
Any
(
x
=>
x
.
AttributeType
==
typeof
(
ExplicitConstructorAttribute
))).
ToList
();
#else
var
withAttr
=
constructors
.
Where
(
c
=>
c
.
GetCustomAttributes
(
typeof
(
ExplicitConstructorAttribute
),
true
).
Length
>
0
).
ToList
();
#endif
if
(
withAttr
.
Count
==
1
)
{
...
...
Dapper/DynamicParameters.cs
浏览文件 @
8152f2c7
...
...
@@ -6,10 +6,6 @@
using
System.Reflection
;
using
System.Reflection.Emit
;
#if NETSTANDARD1_3
using
ApplicationException
=
System
.
InvalidOperationException
;
#endif
namespace
Dapper
{
/// <summary>
...
...
Dapper/SqlDataRecordHandler.cs
浏览文件 @
8152f2c7
...
...
@@ -5,9 +5,7 @@
namespace
Dapper
{
internal
sealed
class
SqlDataRecordHandler
<
T
>
:
SqlMapper
.
ITypeHandler
#if !NETSTANDARD1_3
where
T
:
IDataRecord
#endif
{
public
object
Parse
(
Type
destinationType
,
object
value
)
{
...
...
Dapper/SqlDataRecordListTVPParameter.cs
浏览文件 @
8152f2c7
...
...
@@ -12,9 +12,7 @@ namespace Dapper
/// Used to pass a IEnumerable<SqlDataRecord> as a SqlDataRecordListTVPParameter
/// </summary>
internal
sealed
class
SqlDataRecordListTVPParameter
<
T
>
:
SqlMapper
.
ICustomQueryParameter
#if !NETSTANDARD1_3
where
T
:
IDataRecord
#endif
{
private
readonly
IEnumerable
<
T
>
data
;
private
readonly
string
typeName
;
...
...
Dapper/SqlMapper.Async.cs
浏览文件 @
8152f2c7
...
...
@@ -406,7 +406,7 @@ private static DbCommand TrySetupAsyncCommand(this CommandDefinition command, ID
private
static
async
Task
<
IEnumerable
<
T
>>
QueryAsync
<
T
>(
this
IDbConnection
cnn
,
Type
effectiveType
,
CommandDefinition
command
)
{
object
param
=
command
.
Parameters
;
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
effectiveType
,
param
?.
GetType
()
,
null
);
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
effectiveType
,
param
?.
GetType
());
var
info
=
GetCacheInfo
(
identity
,
param
,
command
.
AddToCache
);
bool
wasClosed
=
cnn
.
State
==
ConnectionState
.
Closed
;
var
cancel
=
command
.
CancellationToken
;
...
...
@@ -470,7 +470,7 @@ private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn,
private
static
async
Task
<
T
>
QueryRowAsync
<
T
>(
this
IDbConnection
cnn
,
Row
row
,
Type
effectiveType
,
CommandDefinition
command
)
{
object
param
=
command
.
Parameters
;
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
effectiveType
,
param
?.
GetType
()
,
null
);
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
effectiveType
,
param
?.
GetType
());
var
info
=
GetCacheInfo
(
identity
,
param
,
command
.
AddToCache
);
bool
wasClosed
=
cnn
.
State
==
ConnectionState
.
Closed
;
var
cancel
=
command
.
CancellationToken
;
...
...
@@ -594,7 +594,7 @@ private static async Task<int> ExecuteMultiImplAsync(IDbConnection cnn, CommandD
isFirst
=
false
;
cmd
=
command
.
TrySetupAsyncCommand
(
cnn
,
null
);
masterSql
=
cmd
.
CommandText
;
var
identity
=
new
Identity
(
command
.
CommandText
,
cmd
.
CommandType
,
cnn
,
null
,
obj
.
GetType
()
,
null
);
var
identity
=
new
Identity
(
command
.
CommandText
,
cmd
.
CommandType
,
cnn
,
null
,
obj
.
GetType
());
info
=
GetCacheInfo
(
identity
,
obj
,
command
.
AddToCache
);
}
else
if
(
pending
.
Count
>=
MAX_PENDING
)
...
...
@@ -642,7 +642,7 @@ private static async Task<int> ExecuteMultiImplAsync(IDbConnection cnn, CommandD
{
masterSql
=
cmd
.
CommandText
;
isFirst
=
false
;
var
identity
=
new
Identity
(
command
.
CommandText
,
cmd
.
CommandType
,
cnn
,
null
,
obj
.
GetType
()
,
null
);
var
identity
=
new
Identity
(
command
.
CommandText
,
cmd
.
CommandType
,
cnn
,
null
,
obj
.
GetType
());
info
=
GetCacheInfo
(
identity
,
obj
,
command
.
AddToCache
);
}
else
...
...
@@ -667,7 +667,7 @@ private static async Task<int> ExecuteMultiImplAsync(IDbConnection cnn, CommandD
private
static
async
Task
<
int
>
ExecuteImplAsync
(
IDbConnection
cnn
,
CommandDefinition
command
,
object
param
)
{
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
null
,
param
?.
GetType
()
,
null
);
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
null
,
param
?.
GetType
());
var
info
=
GetCacheInfo
(
identity
,
param
,
command
.
AddToCache
);
bool
wasClosed
=
cnn
.
State
==
ConnectionState
.
Closed
;
using
(
var
cmd
=
command
.
TrySetupAsyncCommand
(
cnn
,
info
.
ParamReader
))
...
...
@@ -935,7 +935,7 @@ private static async Task<int> ExecuteImplAsync(IDbConnection cnn, CommandDefini
private
static
async
Task
<
IEnumerable
<
TReturn
>>
MultiMapAsync
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TSixth
,
TSeventh
,
TReturn
>(
this
IDbConnection
cnn
,
CommandDefinition
command
,
Delegate
map
,
string
splitOn
)
{
object
param
=
command
.
Parameters
;
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
typeof
(
TFirst
),
param
?.
GetType
(),
new
[]
{
typeof
(
TFirst
),
typeof
(
TSecond
),
typeof
(
TThird
),
typeof
(
TFourth
),
typeof
(
TFifth
),
typeof
(
TSixth
),
typeof
(
TSeventh
)
}
);
var
identity
=
new
Identity
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TSixth
,
TSeventh
>(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
typeof
(
TFirst
),
param
?.
GetType
()
);
var
info
=
GetCacheInfo
(
identity
,
param
,
command
.
AddToCache
);
bool
wasClosed
=
cnn
.
State
==
ConnectionState
.
Closed
;
try
...
...
@@ -985,7 +985,7 @@ private static async Task<IEnumerable<TReturn>> MultiMapAsync<TReturn>(this IDbC
}
object
param
=
command
.
Parameters
;
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
types
[
0
],
param
?.
GetType
(),
types
);
var
identity
=
new
Identity
WithTypes
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
types
[
0
],
param
?.
GetType
(),
types
);
var
info
=
GetCacheInfo
(
identity
,
param
,
command
.
AddToCache
);
bool
wasClosed
=
cnn
.
State
==
ConnectionState
.
Closed
;
try
...
...
@@ -1037,7 +1037,7 @@ private static IEnumerable<T> ExecuteReaderSync<T>(IDataReader reader, Func<IDat
public
static
async
Task
<
GridReader
>
QueryMultipleAsync
(
this
IDbConnection
cnn
,
CommandDefinition
command
)
{
object
param
=
command
.
Parameters
;
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
typeof
(
GridReader
),
param
?.
GetType
()
,
null
);
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
typeof
(
GridReader
),
param
?.
GetType
());
CacheInfo
info
=
GetCacheInfo
(
identity
,
param
,
command
.
AddToCache
);
DbCommand
cmd
=
null
;
...
...
@@ -1233,7 +1233,7 @@ private static async Task<T> ExecuteScalarImplAsync<T>(IDbConnection cnn, Comman
object
param
=
command
.
Parameters
;
if
(
param
!=
null
)
{
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
null
,
param
.
GetType
()
,
null
);
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
null
,
param
.
GetType
());
paramReader
=
GetCacheInfo
(
identity
,
command
.
Parameters
,
command
.
AddToCache
).
ParamReader
;
}
...
...
Dapper/SqlMapper.DapperRow.Descriptor.cs
浏览文件 @
8152f2c7
#
if
!
NETSTANDARD1_3
// needs the component-model API
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
...
...
@@ -104,4 +103,3 @@ public override void SetValue(object component, object value)
}
}
}
#endif
Dapper/SqlMapper.GridReader.cs
浏览文件 @
8152f2c7
...
...
@@ -204,15 +204,7 @@ private T ReadRow<T>(Type type, Row row)
private
IEnumerable
<
TReturn
>
MultiReadInternal
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TSixth
,
TSeventh
,
TReturn
>(
Delegate
func
,
string
splitOn
)
{
var
identity
=
this
.
identity
.
ForGrid
(
typeof
(
TReturn
),
new
Type
[]
{
typeof
(
TFirst
),
typeof
(
TSecond
),
typeof
(
TThird
),
typeof
(
TFourth
),
typeof
(
TFifth
),
typeof
(
TSixth
),
typeof
(
TSeventh
)
},
gridIndex
);
var
identity
=
this
.
identity
.
ForGrid
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TSixth
,
TSeventh
>(
typeof
(
TReturn
),
gridIndex
);
IsConsumed
=
true
;
...
...
Dapper/SqlMapper.IDataReader.cs
浏览文件 @
8152f2c7
...
...
@@ -140,7 +140,7 @@ public static IEnumerable<dynamic> Parse(this IDataReader reader)
{
concreteType
=
concreteType
??
typeof
(
T
);
var
func
=
GetDeserializer
(
concreteType
,
reader
,
startIndex
,
length
,
returnNullIfFirstMissing
);
if
(
concreteType
.
IsValueType
()
)
if
(
concreteType
.
IsValueType
)
{
return
_
=>
(
T
)
func
(
_
);
}
...
...
Dapper/SqlMapper.Identity.cs
浏览文件 @
8152f2c7
using
System
;
using
System.Data
;
using
System.Runtime.CompilerServices
;
namespace
Dapper
{
public
static
partial
class
SqlMapper
{
internal
sealed
class
Identity
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TSixth
,
TSeventh
>
:
Identity
{
private
static
readonly
int
s_typeHash
;
private
static
readonly
int
s_typeCount
=
CountNonTrivial
(
out
s_typeHash
);
internal
Identity
(
string
sql
,
CommandType
?
commandType
,
string
connectionString
,
Type
type
,
Type
parametersType
,
int
gridIndex
=
0
)
:
base
(
sql
,
commandType
,
connectionString
,
type
,
parametersType
,
s_typeHash
,
gridIndex
)
{}
internal
Identity
(
string
sql
,
CommandType
?
commandType
,
IDbConnection
connection
,
Type
type
,
Type
parametersType
,
int
gridIndex
=
0
)
:
base
(
sql
,
commandType
,
connection
.
ConnectionString
,
type
,
parametersType
,
s_typeHash
,
gridIndex
)
{
}
static
int
CountNonTrivial
(
out
int
hashCode
)
{
int
hashCodeLocal
=
0
;
int
count
=
0
;
bool
Map
<
T
>()
{
if
(
typeof
(
T
)
!=
typeof
(
DontMap
))
{
count
++;
hashCodeLocal
=
(
hashCodeLocal
*
23
)
+
(
typeof
(
T
).
GetHashCode
());
return
true
;
}
return
false
;
}
_
=
Map
<
TFirst
>()
&&
Map
<
TSecond
>()
&&
Map
<
TThird
>()
&&
Map
<
TFourth
>()
&&
Map
<
TFifth
>()
&&
Map
<
TSixth
>()
&&
Map
<
TSeventh
>();
hashCode
=
hashCodeLocal
;
return
count
;
}
internal
override
int
TypeCount
=>
s_typeCount
;
internal
override
Type
GetType
(
int
index
)
{
switch
(
index
)
{
case
0
:
return
typeof
(
TFirst
);
case
1
:
return
typeof
(
TSecond
);
case
2
:
return
typeof
(
TThird
);
case
3
:
return
typeof
(
TFourth
);
case
4
:
return
typeof
(
TFifth
);
case
5
:
return
typeof
(
TSixth
);
case
6
:
return
typeof
(
TSeventh
);
default
:
return
base
.
GetType
(
index
);
}
}
}
internal
sealed
class
IdentityWithTypes
:
Identity
{
private
readonly
Type
[]
_types
;
internal
IdentityWithTypes
(
string
sql
,
CommandType
?
commandType
,
string
connectionString
,
Type
type
,
Type
parametersType
,
Type
[]
otherTypes
,
int
gridIndex
=
0
)
:
base
(
sql
,
commandType
,
connectionString
,
type
,
parametersType
,
HashTypes
(
otherTypes
),
gridIndex
)
{
_types
=
otherTypes
??
Type
.
EmptyTypes
;
}
internal
IdentityWithTypes
(
string
sql
,
CommandType
?
commandType
,
IDbConnection
connection
,
Type
type
,
Type
parametersType
,
Type
[]
otherTypes
,
int
gridIndex
=
0
)
:
base
(
sql
,
commandType
,
connection
.
ConnectionString
,
type
,
parametersType
,
HashTypes
(
otherTypes
),
gridIndex
)
{
_types
=
otherTypes
??
Type
.
EmptyTypes
;
}
internal
override
int
TypeCount
=>
_types
.
Length
;
internal
override
Type
GetType
(
int
index
)
=>
_types
[
index
];
static
int
HashTypes
(
Type
[]
types
)
{
var
hashCode
=
0
;
if
(
types
!=
null
)
{
foreach
(
var
t
in
types
)
{
hashCode
=
(
hashCode
*
23
)
+
(
t
?.
GetHashCode
()
??
0
);
}
}
return
hashCode
;
}
}
/// <summary>
/// Identity of a cached query in Dapper, used for extensibility.
/// </summary>
public
class
Identity
:
IEquatable
<
Identity
>
{
internal
virtual
int
TypeCount
=>
0
;
internal
virtual
Type
GetType
(
int
index
)
=>
throw
new
IndexOutOfRangeException
(
nameof
(
index
));
internal
Identity
ForGrid
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TSixth
,
TSeventh
>(
Type
primaryType
,
int
gridIndex
)
=>
new
Identity
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TSixth
,
TSeventh
>(
sql
,
commandType
,
connectionString
,
primaryType
,
parametersType
,
gridIndex
);
internal
Identity
ForGrid
(
Type
primaryType
,
int
gridIndex
)
=>
new
Identity
(
sql
,
commandType
,
connectionString
,
primaryType
,
parametersType
,
null
,
gridIndex
);
new
Identity
(
sql
,
commandType
,
connectionString
,
primaryType
,
parametersType
,
0
,
gridIndex
);
internal
Identity
ForGrid
(
Type
primaryType
,
Type
[]
otherTypes
,
int
gridIndex
)
=>
new
Identity
(
sql
,
commandType
,
connectionString
,
primaryType
,
parametersType
,
otherTypes
,
gridIndex
);
(
otherTypes
==
null
||
otherTypes
.
Length
==
0
)
?
new
Identity
(
sql
,
commandType
,
connectionString
,
primaryType
,
parametersType
,
0
,
gridIndex
)
:
new
IdentityWithTypes
(
sql
,
commandType
,
connectionString
,
primaryType
,
parametersType
,
otherTypes
,
gridIndex
);
/// <summary>
/// Create an identity for use with DynamicParameters, internal use only.
...
...
@@ -22,12 +113,12 @@ public class Identity : IEquatable<Identity>
/// <param name="type">The parameters type to create an <see cref="Identity"/> for.</param>
/// <returns></returns>
public
Identity
ForDynamicParameters
(
Type
type
)
=>
new
Identity
(
sql
,
commandType
,
connectionString
,
this
.
type
,
type
,
null
,
-
1
);
new
Identity
(
sql
,
commandType
,
connectionString
,
this
.
type
,
type
,
0
,
-
1
);
internal
Identity
(
string
sql
,
CommandType
?
commandType
,
IDbConnection
connection
,
Type
type
,
Type
parametersType
,
Type
[]
otherTypes
)
:
this
(
sql
,
commandType
,
connection
.
ConnectionString
,
type
,
parametersType
,
otherTypes
,
0
)
{
/* base call */
}
internal
Identity
(
string
sql
,
CommandType
?
commandType
,
IDbConnection
connection
,
Type
type
,
Type
parametersType
)
:
this
(
sql
,
commandType
,
connection
.
ConnectionString
,
type
,
parametersType
,
0
,
0
)
{
/* base call */
}
private
Identity
(
string
sql
,
CommandType
?
commandType
,
string
connectionString
,
Type
type
,
Type
parametersType
,
Type
[]
otherTypes
,
int
gridIndex
)
private
protected
Identity
(
string
sql
,
CommandType
?
commandType
,
string
connectionString
,
Type
type
,
Type
parametersType
,
int
otherTypesHash
,
int
gridIndex
)
{
this
.
sql
=
sql
;
this
.
commandType
=
commandType
;
...
...
@@ -42,13 +133,7 @@ private Identity(string sql, CommandType? commandType, string connectionString,
hashCode
=
(
hashCode
*
23
)
+
gridIndex
.
GetHashCode
();
hashCode
=
(
hashCode
*
23
)
+
(
sql
?.
GetHashCode
()
??
0
);
hashCode
=
(
hashCode
*
23
)
+
(
type
?.
GetHashCode
()
??
0
);
if
(
otherTypes
!=
null
)
{
foreach
(
var
t
in
otherTypes
)
{
hashCode
=
(
hashCode
*
23
)
+
(
t
?.
GetHashCode
()
??
0
);
}
}
hashCode
=
(
hashCode
*
23
)
+
otherTypesHash
;
hashCode
=
(
hashCode
*
23
)
+
(
connectionString
==
null
?
0
:
connectionStringComparer
.
GetHashCode
(
connectionString
));
hashCode
=
(
hashCode
*
23
)
+
(
parametersType
?.
GetHashCode
()
??
0
);
}
...
...
@@ -101,6 +186,11 @@ private Identity(string sql, CommandType? commandType, string connectionString,
/// <returns></returns>
public
override
int
GetHashCode
()
=>
hashCode
;
/// <summary>
/// See object.ToString()
/// </summary>
public
override
string
ToString
()
=>
sql
;
/// <summary>
/// Compare 2 Identity objects
/// </summary>
...
...
@@ -108,13 +198,30 @@ private Identity(string sql, CommandType? commandType, string connectionString,
/// <returns>Whether the two are equal</returns>
public
bool
Equals
(
Identity
other
)
{
return
other
!=
null
&&
gridIndex
==
other
.
gridIndex
if
(
ReferenceEquals
(
this
,
other
))
return
true
;
if
(
ReferenceEquals
(
other
,
null
))
return
false
;
int
typeCount
;
return
gridIndex
==
other
.
gridIndex
&&
type
==
other
.
type
&&
sql
==
other
.
sql
&&
commandType
==
other
.
commandType
&&
connectionStringComparer
.
Equals
(
connectionString
,
other
.
connectionString
)
&&
parametersType
==
other
.
parametersType
;
&&
parametersType
==
other
.
parametersType
&&
(
typeCount
=
TypeCount
)
==
other
.
TypeCount
&&
(
typeCount
==
0
||
TypesEqual
(
this
,
other
,
typeCount
));
}
[
MethodImpl
(
MethodImplOptions
.
NoInlining
)]
private
static
bool
TypesEqual
(
Identity
x
,
Identity
y
,
int
count
)
{
if
(
y
.
TypeCount
!=
count
)
return
false
;
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
if
(
x
.
GetType
(
i
)
!=
y
.
GetType
(
i
))
return
false
;
}
return
true
;
}
}
}
...
...
Dapper/SqlMapper.TypeHandlerCache.cs
浏览文件 @
8152f2c7
...
...
@@ -11,9 +11,7 @@ public static partial class SqlMapper
/// </summary>
/// <typeparam name="T">The type to have a cache for.</typeparam>
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
#if !NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
public
static
class
TypeHandlerCache
<
T
>
{
...
...
Dapper/SqlMapper.cs
浏览文件 @
8152f2c7
...
...
@@ -12,17 +12,12 @@
using
System.Linq
;
using
System.Reflection
;
using
System.Reflection.Emit
;
using
System.Runtime.CompilerServices
;
using
System.Text
;
using
System.Text.RegularExpressions
;
using
System.Threading
;
using
System.Xml
;
using
System.Xml.Linq
;
#if NETSTANDARD1_3
using
DataException
=
System
.
InvalidOperationException
;
#endif
namespace
Dapper
{
/// <summary>
...
...
@@ -221,25 +216,12 @@ static SqlMapper()
private
static
void
ResetTypeHandlers
(
bool
clone
)
{
typeHandlers
=
new
Dictionary
<
Type
,
ITypeHandler
>();
#if !NETSTANDARD1_3
AddTypeHandlerImpl
(
typeof
(
DataTable
),
new
DataTableHandler
(),
clone
);
#endif
try
{
AddSqlDataRecordsTypeHandler
(
clone
);
}
catch
{
/* https://github.com/StackExchange/dapper-dot-net/issues/424 */
}
AddTypeHandlerImpl
(
typeof
(
XmlDocument
),
new
XmlDocumentHandler
(),
clone
);
AddTypeHandlerImpl
(
typeof
(
XDocument
),
new
XDocumentHandler
(),
clone
);
AddTypeHandlerImpl
(
typeof
(
XElement
),
new
XElementHandler
(),
clone
);
}
[
MethodImpl
(
MethodImplOptions
.
NoInlining
)]
private
static
void
AddSqlDataRecordsTypeHandler
(
bool
clone
)
{
AddTypeHandlerImpl
(
typeof
(
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>),
new
SqlDataRecordHandler
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>(),
clone
);
}
/// <summary>
/// Configure the specified type to be mapped to a given db-type.
/// </summary>
...
...
@@ -292,7 +274,7 @@ public static void AddTypeHandlerImpl(Type type, ITypeHandler handler, bool clon
if
(
type
==
null
)
throw
new
ArgumentNullException
(
nameof
(
type
));
Type
secondary
=
null
;
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
var
underlying
=
Nullable
.
GetUnderlyingType
(
type
);
if
(
underlying
==
null
)
...
...
@@ -350,9 +332,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 !NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
public
static
DbType
GetDbType
(
object
value
)
{
...
...
@@ -369,16 +349,14 @@ 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 !NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
public
static
DbType
LookupDbType
(
Type
type
,
string
name
,
bool
demand
,
out
ITypeHandler
handler
)
{
handler
=
null
;
var
nullUnderlyingType
=
Nullable
.
GetUnderlyingType
(
type
);
if
(
nullUnderlyingType
!=
null
)
type
=
nullUnderlyingType
;
if
(
type
.
IsEnum
()
&&
!
typeMap
.
ContainsKey
(
type
))
if
(
type
.
IsEnum
&&
!
typeMap
.
ContainsKey
(
type
))
{
type
=
Enum
.
GetUnderlyingType
(
type
);
}
...
...
@@ -396,10 +374,30 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
}
if
(
typeof
(
IEnumerable
).
IsAssignableFrom
(
type
))
{
// auto-detect things like IEnumerable<SqlDataRecord> as a family
if
(
type
.
IsInterface
&&
type
.
IsGenericType
&&
type
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>)
&&
typeof
(
IEnumerable
<
IDataRecord
>).
IsAssignableFrom
(
type
))
{
var
argTypes
=
type
.
GetGenericArguments
();
if
(
typeof
(
IDataRecord
).
IsAssignableFrom
(
argTypes
[
0
]))
{
try
{
handler
=
(
ITypeHandler
)
Activator
.
CreateInstance
(
typeof
(
SqlDataRecordHandler
<>).
MakeGenericType
(
argTypes
));
AddTypeHandlerImpl
(
type
,
handler
,
true
);
return
DbType
.
Object
;
}
catch
{
handler
=
null
;
}
}
}
return
DynamicParameters
.
EnumerableMultiParameter
;
}
#if !NETSTANDARD1_3 && !NETSTANDARD2_0
switch
(
type
.
FullName
)
{
case
"Microsoft.SqlServer.Types.SqlGeography"
:
...
...
@@ -412,7 +410,7 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
AddTypeHandler
(
type
,
handler
=
new
UdtTypeHandler
(
"hierarchyid"
));
return
DbType
.
Object
;
}
#endif
if
(
demand
)
throw
new
NotSupportedException
(
$"The member
{
name
}
of type
{
type
.
FullName
}
cannot be used as a parameter value"
);
return
DbType
.
Object
;
...
...
@@ -540,7 +538,7 @@ private static int ExecuteImpl(this IDbConnection cnn, ref CommandDefinition com
{
masterSql
=
cmd
.
CommandText
;
isFirst
=
false
;
identity
=
new
Identity
(
command
.
CommandText
,
cmd
.
CommandType
,
cnn
,
null
,
obj
.
GetType
()
,
null
);
identity
=
new
Identity
(
command
.
CommandText
,
cmd
.
CommandType
,
cnn
,
null
,
obj
.
GetType
());
info
=
GetCacheInfo
(
identity
,
obj
,
command
.
AddToCache
);
}
else
...
...
@@ -564,7 +562,7 @@ private static int ExecuteImpl(this IDbConnection cnn, ref CommandDefinition com
// nice and simple
if
(
param
!=
null
)
{
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
null
,
param
.
GetType
()
,
null
);
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
null
,
param
.
GetType
());
info
=
GetCacheInfo
(
identity
,
param
,
command
.
AddToCache
);
}
return
ExecuteCommand
(
cnn
,
ref
command
,
param
==
null
?
null
:
info
.
ParamReader
);
...
...
@@ -1009,7 +1007,7 @@ public static GridReader QueryMultiple(this IDbConnection cnn, string sql, objec
private
static
GridReader
QueryMultipleImpl
(
this
IDbConnection
cnn
,
ref
CommandDefinition
command
)
{
object
param
=
command
.
Parameters
;
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
typeof
(
GridReader
),
param
?.
GetType
()
,
null
);
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
typeof
(
GridReader
),
param
?.
GetType
());
CacheInfo
info
=
GetCacheInfo
(
identity
,
param
,
command
.
AddToCache
);
IDbCommand
cmd
=
null
;
...
...
@@ -1066,7 +1064,7 @@ private static IDataReader ExecuteReaderWithFlagsFallback(IDbCommand cmd, bool w
private
static
IEnumerable
<
T
>
QueryImpl
<
T
>(
this
IDbConnection
cnn
,
CommandDefinition
command
,
Type
effectiveType
)
{
object
param
=
command
.
Parameters
;
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
effectiveType
,
param
?.
GetType
()
,
null
);
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
effectiveType
,
param
?.
GetType
());
var
info
=
GetCacheInfo
(
identity
,
param
,
command
.
AddToCache
);
IDbCommand
cmd
=
null
;
...
...
@@ -1164,7 +1162,7 @@ private static void ThrowZeroRows(Row row)
private
static
T
QueryRowImpl
<
T
>(
IDbConnection
cnn
,
Row
row
,
ref
CommandDefinition
command
,
Type
effectiveType
)
{
object
param
=
command
.
Parameters
;
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
effectiveType
,
param
?.
GetType
()
,
null
);
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
effectiveType
,
param
?.
GetType
());
var
info
=
GetCacheInfo
(
identity
,
param
,
command
.
AddToCache
);
IDbCommand
cmd
=
null
;
...
...
@@ -1407,7 +1405,7 @@ public static IEnumerable<TReturn> Query<TReturn>(this IDbConnection cnn, string
private
static
IEnumerable
<
TReturn
>
MultiMapImpl
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TSixth
,
TSeventh
,
TReturn
>(
this
IDbConnection
cnn
,
CommandDefinition
command
,
Delegate
map
,
string
splitOn
,
IDataReader
reader
,
Identity
identity
,
bool
finalize
)
{
object
param
=
command
.
Parameters
;
identity
=
identity
??
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
typeof
(
TFirst
),
param
?.
GetType
(),
new
[]
{
typeof
(
TFirst
),
typeof
(
TSecond
),
typeof
(
TThird
),
typeof
(
TFourth
),
typeof
(
TFifth
),
typeof
(
TSixth
),
typeof
(
TSeventh
)
}
);
identity
=
identity
??
new
Identity
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TSixth
,
TSeventh
>(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
typeof
(
TFirst
),
param
?.
GetType
()
);
CacheInfo
cinfo
=
GetCacheInfo
(
identity
,
param
,
command
.
AddToCache
);
IDbCommand
ownedCommand
=
null
;
...
...
@@ -1429,7 +1427,7 @@ public static IEnumerable<TReturn> Query<TReturn>(this IDbConnection cnn, string
int
hash
=
GetColumnHash
(
reader
);
if
((
deserializer
=
cinfo
.
Deserializer
).
Func
==
null
||
(
otherDeserializers
=
cinfo
.
OtherDeserializers
)
==
null
||
hash
!=
deserializer
.
Hash
)
{
var
deserializers
=
GenerateDeserializers
(
new
[]
{
typeof
(
TFirst
),
typeof
(
TSecond
),
typeof
(
TThird
),
typeof
(
TFourth
),
typeof
(
TFifth
),
typeof
(
TSixth
),
typeof
(
TSeventh
)
}
,
splitOn
,
reader
);
var
deserializers
=
GenerateDeserializers
(
identity
,
splitOn
,
reader
);
deserializer
=
cinfo
.
Deserializer
=
new
DeserializerState
(
hash
,
deserializers
[
0
]);
otherDeserializers
=
cinfo
.
OtherDeserializers
=
deserializers
.
Skip
(
1
).
ToArray
();
if
(
command
.
AddToCache
)
SetQueryCache
(
identity
,
cinfo
);
...
...
@@ -1477,7 +1475,7 @@ private static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn
}
object
param
=
command
.
Parameters
;
identity
=
identity
??
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
types
[
0
],
param
?.
GetType
(),
types
);
identity
=
identity
??
new
Identity
WithTypes
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
types
[
0
],
param
?.
GetType
(),
types
);
CacheInfo
cinfo
=
GetCacheInfo
(
identity
,
param
,
command
.
AddToCache
);
IDbCommand
ownedCommand
=
null
;
...
...
@@ -1499,7 +1497,7 @@ private static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn
int
hash
=
GetColumnHash
(
reader
);
if
((
deserializer
=
cinfo
.
Deserializer
).
Func
==
null
||
(
otherDeserializers
=
cinfo
.
OtherDeserializers
)
==
null
||
hash
!=
deserializer
.
Hash
)
{
var
deserializers
=
GenerateDeserializers
(
types
,
splitOn
,
reader
);
var
deserializers
=
GenerateDeserializers
(
identity
,
splitOn
,
reader
);
deserializer
=
cinfo
.
Deserializer
=
new
DeserializerState
(
hash
,
deserializers
[
0
]);
otherDeserializers
=
cinfo
.
OtherDeserializers
=
deserializers
.
Skip
(
1
).
ToArray
();
SetQueryCache
(
identity
,
cinfo
);
...
...
@@ -1571,12 +1569,14 @@ private static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn
};
}
private
static
Func
<
IDataReader
,
object
>[]
GenerateDeserializers
(
Type
[]
types
,
string
splitOn
,
IDataReader
reader
)
private
static
Func
<
IDataReader
,
object
>[]
GenerateDeserializers
(
Identity
identity
,
string
splitOn
,
IDataReader
reader
)
{
var
deserializers
=
new
List
<
Func
<
IDataReader
,
object
>>();
var
splits
=
splitOn
.
Split
(
','
).
Select
(
s
=>
s
.
Trim
()).
ToArray
();
bool
isMultiSplit
=
splits
.
Length
>
1
;
if
(
types
[
0
]
==
typeof
(
object
))
int
typeCount
=
identity
.
TypeCount
;
if
(
identity
.
GetType
(
0
)
==
typeof
(
object
))
{
// we go left to right for dynamic multi-mapping so that the madness of TestMultiMappingVariations
// is supported
...
...
@@ -1584,8 +1584,10 @@ private static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn
int
currentPos
=
0
;
int
splitIdx
=
0
;
string
currentSplit
=
splits
[
splitIdx
];
foreach
(
var
type
in
types
)
for
(
int
i
=
0
;
i
<
typeCount
;
i
++)
{
Type
type
=
identity
.
GetType
(
i
);
if
(
type
==
typeof
(
DontMap
))
{
break
;
...
...
@@ -1608,9 +1610,9 @@ private static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn
int
currentPos
=
reader
.
FieldCount
;
int
splitIdx
=
splits
.
Length
-
1
;
var
currentSplit
=
splits
[
splitIdx
];
for
(
var
typeIdx
=
type
s
.
Length
-
1
;
typeIdx
>=
0
;
--
typeIdx
)
for
(
var
typeIdx
=
type
Count
-
1
;
typeIdx
>=
0
;
--
typeIdx
)
{
var
type
=
types
[
typeIdx
]
;
var
type
=
identity
.
GetType
(
typeIdx
)
;
if
(
type
==
typeof
(
DontMap
))
{
continue
;
...
...
@@ -1775,8 +1777,8 @@ private static void PassByPosition(IDbCommand cmd)
return
GetDapperRowDeserializer
(
reader
,
startBound
,
length
,
returnNullIfFirstMissing
);
}
Type
underlyingType
=
null
;
if
(!(
typeMap
.
ContainsKey
(
type
)
||
type
.
IsEnum
()
||
type
.
FullName
==
LinqBinary
||
(
type
.
IsValueType
()
&&
(
underlyingType
=
Nullable
.
GetUnderlyingType
(
type
))
!=
null
&&
underlyingType
.
IsEnum
()
)))
if
(!(
typeMap
.
ContainsKey
(
type
)
||
type
.
IsEnum
||
type
.
FullName
==
LinqBinary
||
(
type
.
IsValueType
&&
(
underlyingType
=
Nullable
.
GetUnderlyingType
(
type
))
!=
null
&&
underlyingType
.
IsEnum
)))
{
if
(
typeHandlers
.
TryGetValue
(
type
,
out
ITypeHandler
handler
))
{
...
...
@@ -1868,9 +1870,7 @@ private static Exception MultiMapException(IDataRecord reader)
/// Internal use only.
/// </summary>
/// <param name="value">The object to convert to a character.</param>
#if !NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
public
static
char
ReadChar
(
object
value
)
...
...
@@ -1885,9 +1885,7 @@ public static char ReadChar(object value)
/// Internal use only.
/// </summary>
/// <param name="value">The object to convert to a character.</param>
#if !NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
public
static
char
?
ReadNullableChar
(
object
value
)
...
...
@@ -1904,9 +1902,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 !NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
true
)]
public
static
IDbDataParameter
FindOrAddParameter
(
IDataParameterCollection
parameters
,
IDbCommand
command
,
string
name
)
...
...
@@ -1962,9 +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 !NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
public
static
void
PackListParameters
(
IDbCommand
command
,
string
namePrefix
,
object
value
)
...
...
@@ -2206,7 +2200,7 @@ public static object SanitizeParameterValue(object value)
}
else
{
typeCode
=
Type
Extensions
.
GetTypeCode
(
Enum
.
GetUnderlyingType
(
value
.
GetType
()));
typeCode
=
Type
.
GetTypeCode
(
Enum
.
GetUnderlyingType
(
value
.
GetType
()));
}
switch
(
typeCode
)
{
...
...
@@ -2265,12 +2259,10 @@ public static string Format(object value)
}
else
{
switch
(
Type
Extensions
.
GetTypeCode
(
value
.
GetType
()))
switch
(
Type
.
GetTypeCode
(
value
.
GetType
()))
{
#if !NETSTANDARD1_3
case
TypeCode
.
DBNull
:
return
"null"
;
#endif
case
TypeCode
.
Boolean
:
return
((
bool
)
value
)
?
"1"
:
"0"
;
case
TypeCode
.
Byte
:
...
...
@@ -2370,7 +2362,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
public
static
Action
<
IDbCommand
,
object
>
CreateParamInfoGenerator
(
Identity
identity
,
bool
checkForDuplicates
,
bool
removeUnused
)
=>
CreateParamInfoGenerator
(
identity
,
checkForDuplicates
,
removeUnused
,
GetLiteralTokens
(
identity
.
sql
));
private
static
bool
IsValueTuple
(
Type
type
)
=>
type
?.
IsValueType
()
==
true
&&
type
.
FullName
.
StartsWith
(
"System.ValueTuple`"
,
StringComparison
.
Ordinal
);
private
static
bool
IsValueTuple
(
Type
type
)
=>
type
?.
IsValueType
==
true
&&
type
.
FullName
.
StartsWith
(
"System.ValueTuple`"
,
StringComparison
.
Ordinal
);
internal
static
Action
<
IDbCommand
,
object
>
CreateParamInfoGenerator
(
Identity
identity
,
bool
checkForDuplicates
,
bool
removeUnused
,
IList
<
LiteralToken
>
literals
)
{
...
...
@@ -2390,8 +2382,9 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
var
il
=
dm
.
GetILGenerator
();
bool
isStruct
=
type
.
IsValueType
();
var
sizeLocal
=
(
LocalBuilder
)
null
;
bool
isStruct
=
type
.
IsValueType
;
var
_sizeLocal
=
(
LocalBuilder
)
null
;
LocalBuilder
GetSizeLocal
()
=>
_sizeLocal
??
(
_sizeLocal
=
il
.
DeclareLocal
(
typeof
(
int
)));
il
.
Emit
(
OpCodes
.
Ldarg_1
);
// stack is now [untyped-param]
LocalBuilder
typedParameterLocal
;
...
...
@@ -2501,7 +2494,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
il
.
Emit
(
OpCodes
.
Ldstr
,
prop
.
Name
);
// stack is now [parameters] [command] [name]
il
.
Emit
(
OpCodes
.
Ldloc
,
typedParameterLocal
);
// stack is now [parameters] [command] [name] [typed-param]
il
.
Emit
(
callOpCode
,
prop
.
GetGetMethod
());
// stack is [parameters] [command] [name] [typed-value]
if
(
prop
.
PropertyType
.
IsValueType
()
)
if
(
prop
.
PropertyType
.
IsValueType
)
{
il
.
Emit
(
OpCodes
.
Box
,
prop
.
PropertyType
);
// stack is [parameters] [command] [name] [boxed-value]
}
...
...
@@ -2553,13 +2546,13 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
il
.
Emit
(
OpCodes
.
Ldloc
,
typedParameterLocal
);
// stack is now [parameters] [[parameters]] [parameter] [parameter] [typed-param]
il
.
Emit
(
callOpCode
,
prop
.
GetGetMethod
());
// stack is [parameters] [[parameters]] [parameter] [parameter] [typed-value]
bool
checkForNull
;
if
(
prop
.
PropertyType
.
IsValueType
()
)
if
(
prop
.
PropertyType
.
IsValueType
)
{
var
propType
=
prop
.
PropertyType
;
var
nullType
=
Nullable
.
GetUnderlyingType
(
propType
);
bool
callSanitize
=
false
;
if
((
nullType
??
propType
).
IsEnum
()
)
if
((
nullType
??
propType
).
IsEnum
)
{
if
(
nullType
!=
null
)
{
...
...
@@ -2571,7 +2564,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
{
checkForNull
=
false
;
// non-nullable enum; we can do that! just box to the wrong type! (no, really)
switch
(
Type
Extensions
.
GetTypeCode
(
Enum
.
GetUnderlyingType
(
propType
)))
switch
(
Type
.
GetTypeCode
(
Enum
.
GetUnderlyingType
(
propType
)))
{
case
TypeCode
.
Byte
:
propType
=
typeof
(
byte
);
break
;
case
TypeCode
.
SByte
:
propType
=
typeof
(
sbyte
);
break
;
...
...
@@ -2602,10 +2595,6 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
}
if
(
checkForNull
)
{
if
((
dbType
==
DbType
.
String
||
dbType
==
DbType
.
AnsiString
)
&&
sizeLocal
==
null
)
{
sizeLocal
=
il
.
DeclareLocal
(
typeof
(
int
));
}
// relative stack: [boxed value]
il
.
Emit
(
OpCodes
.
Dup
);
// relative stack: [boxed value] [boxed value]
Label
notNull
=
il
.
DefineLabel
();
...
...
@@ -2617,7 +2606,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
if
(
dbType
==
DbType
.
String
||
dbType
==
DbType
.
AnsiString
)
{
EmitInt32
(
il
,
0
);
il
.
Emit
(
OpCodes
.
Stloc
,
sizeLocal
);
il
.
Emit
(
OpCodes
.
Stloc
,
GetSizeLocal
()
);
}
if
(
allDone
!=
null
)
il
.
Emit
(
OpCodes
.
Br_S
,
allDone
.
Value
);
il
.
MarkLabel
(
notNull
);
...
...
@@ -2634,7 +2623,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
il
.
MarkLabel
(
isLong
);
EmitInt32
(
il
,
-
1
);
// [string] [-1]
il
.
MarkLabel
(
lenDone
);
il
.
Emit
(
OpCodes
.
Stloc
,
sizeLocal
);
// [string]
il
.
Emit
(
OpCodes
.
Stloc
,
GetSizeLocal
()
);
// [string]
}
if
(
prop
.
PropertyType
.
FullName
==
LinqBinary
)
{
...
...
@@ -2658,6 +2647,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
if
(
prop
.
PropertyType
==
typeof
(
string
))
{
var
endOfSize
=
il
.
DefineLabel
();
var
sizeLocal
=
GetSizeLocal
();
// don't set if 0
il
.
Emit
(
OpCodes
.
Ldloc
,
sizeLocal
);
// [parameters] [[parameters]] [parameter] [size]
il
.
Emit
(
OpCodes
.
Brfalse_S
,
endOfSize
);
// [parameters] [[parameters]] [parameter]
...
...
@@ -2719,7 +2709,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
il
.
Emit
(
OpCodes
.
Ldloc
,
typedParameterLocal
);
// command, sql, typed parameter
il
.
EmitCall
(
callOpCode
,
prop
.
GetGetMethod
(),
null
);
// command, sql, typed value
Type
propType
=
prop
.
PropertyType
;
var
typeCode
=
Type
Extensions
.
GetTypeCode
(
propType
);
var
typeCode
=
Type
.
GetTypeCode
(
propType
);
switch
(
typeCode
)
{
case
TypeCode
.
Boolean
:
...
...
@@ -2768,7 +2758,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
il
.
EmitCall
(
OpCodes
.
Call
,
convert
,
null
);
// command, sql, string value
break
;
default
:
if
(
propType
.
IsValueType
()
)
il
.
Emit
(
OpCodes
.
Box
,
propType
);
// command, sql, object value
if
(
propType
.
IsValueType
)
il
.
Emit
(
OpCodes
.
Box
,
propType
);
// command, sql, object value
il
.
EmitCall
(
OpCodes
.
Call
,
format
,
null
);
// command, sql, string value
break
;
}
...
...
@@ -2786,7 +2776,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
{
typeof
(
bool
),
typeof
(
sbyte
),
typeof
(
byte
),
typeof
(
ushort
),
typeof
(
short
),
typeof
(
uint
),
typeof
(
int
),
typeof
(
ulong
),
typeof
(
long
),
typeof
(
float
),
typeof
(
double
),
typeof
(
decimal
)
}.
ToDictionary
(
x
=>
Type
Extensions
.
GetTypeCode
(
x
),
x
=>
x
.
GetPublicInstanceMethod
(
nameof
(
object
.
ToString
),
new
[]
{
typeof
(
IFormatProvider
)
}));
}.
ToDictionary
(
x
=>
Type
.
GetTypeCode
(
x
),
x
=>
x
.
GetPublicInstanceMethod
(
nameof
(
object
.
ToString
),
new
[]
{
typeof
(
IFormatProvider
)
}));
private
static
MethodInfo
GetToString
(
TypeCode
typeCode
)
{
...
...
@@ -2821,7 +2811,7 @@ private static T ExecuteScalarImpl<T>(IDbConnection cnn, ref CommandDefinition c
object
param
=
command
.
Parameters
;
if
(
param
!=
null
)
{
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
null
,
param
.
GetType
()
,
null
);
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
null
,
param
.
GetType
());
paramReader
=
GetCacheInfo
(
identity
,
command
.
Parameters
,
command
.
AddToCache
).
ParamReader
;
}
...
...
@@ -2878,7 +2868,7 @@ private static IDataReader ExecuteReaderImpl(IDbConnection cnn, ref CommandDefin
// nice and simple
if
(
param
!=
null
)
{
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
null
,
param
.
GetType
()
,
null
);
var
identity
=
new
Identity
(
command
.
CommandText
,
command
.
CommandType
,
cnn
,
null
,
param
.
GetType
());
info
=
GetCacheInfo
(
identity
,
param
,
command
.
AddToCache
);
}
var
paramReader
=
info
?.
ParamReader
;
...
...
@@ -2903,7 +2893,7 @@ private static IDataReader ExecuteReaderImpl(IDbConnection cnn, ref CommandDefin
}
#pragma warning restore 618
if
(
effectiveType
.
IsEnum
()
)
if
(
effectiveType
.
IsEnum
)
{
// assume the value is returned as the correct type (int/byte/etc), but box back to the typed enum
return
r
=>
{
...
...
@@ -2936,7 +2926,7 @@ private static T Parse<T>(object value)
if
(
value
is
T
)
return
(
T
)
value
;
var
type
=
typeof
(
T
);
type
=
Nullable
.
GetUnderlyingType
(
type
)
??
type
;
if
(
type
.
IsEnum
()
)
if
(
type
.
IsEnum
)
{
if
(
value
is
float
||
value
is
double
||
value
is
decimal
)
{
...
...
@@ -3069,7 +3059,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
throw
MultiMapException
(
reader
);
}
var
returnType
=
type
.
IsValueType
()
?
typeof
(
object
)
:
type
;
var
returnType
=
type
.
IsValueType
?
typeof
(
object
)
:
type
;
var
dm
=
new
DynamicMethod
(
"Deserialize"
+
Guid
.
NewGuid
().
ToString
(),
returnType
,
new
[]
{
typeof
(
IDataReader
)
},
type
,
true
);
var
il
=
dm
.
GetILGenerator
();
...
...
@@ -3191,11 +3181,9 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
int
index
=
startBound
;
ConstructorInfo
specializedConstructor
=
null
;
#if !NETSTANDARD1_3
bool
supportInitialize
=
false
;
#endif
Dictionary
<
Type
,
LocalBuilder
>
structLocals
=
null
;
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
il
.
Emit
(
OpCodes
.
Ldloca
,
returnValueLocal
);
il
.
Emit
(
OpCodes
.
Initobj
,
type
);
...
...
@@ -3214,7 +3202,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
var
consPs
=
explicitConstr
.
GetParameters
();
foreach
(
var
p
in
consPs
)
{
if
(!
p
.
ParameterType
.
IsValueType
()
)
if
(!
p
.
ParameterType
.
IsValueType
)
{
il
.
Emit
(
OpCodes
.
Ldnull
);
}
...
...
@@ -3226,14 +3214,12 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
il
.
Emit
(
OpCodes
.
Newobj
,
explicitConstr
);
il
.
Emit
(
OpCodes
.
Stloc
,
returnValueLocal
);
#if !NETSTANDARD1_3
supportInitialize
=
typeof
(
ISupportInitialize
).
IsAssignableFrom
(
type
);
if
(
supportInitialize
)
{
il
.
Emit
(
OpCodes
.
Ldloc
,
returnValueLocal
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
nameof
(
ISupportInitialize
.
BeginInit
)),
null
);
}
#endif
}
else
{
...
...
@@ -3248,14 +3234,12 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
{
il
.
Emit
(
OpCodes
.
Newobj
,
ctor
);
il
.
Emit
(
OpCodes
.
Stloc
,
returnValueLocal
);
#if !NETSTANDARD1_3
supportInitialize
=
typeof
(
ISupportInitialize
).
IsAssignableFrom
(
type
);
if
(
supportInitialize
)
{
il
.
Emit
(
OpCodes
.
Ldloc
,
returnValueLocal
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
nameof
(
ISupportInitialize
.
BeginInit
)),
null
);
}
#endif
}
else
{
...
...
@@ -3265,7 +3249,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
}
il
.
BeginExceptionBlock
();
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
il
.
Emit
(
OpCodes
.
Ldloca
,
returnValueLocal
);
// [target]
}
...
...
@@ -3279,7 +3263,6 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
:
names
.
Select
(
n
=>
typeMap
.
GetMember
(
n
))).
ToList
();
// stack is now [target]
bool
first
=
true
;
var
allDone
=
il
.
DefineLabel
();
var
stringEnumLocal
=
(
LocalBuilder
)
null
;
...
...
@@ -3305,7 +3288,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
// Store the value in the property/field
if
(
item
.
Property
!=
null
)
{
il
.
Emit
(
type
.
IsValueType
()
?
OpCodes
.
Call
:
OpCodes
.
Callvirt
,
DefaultTypeMap
.
GetPropertySetter
(
item
.
Property
,
type
));
il
.
Emit
(
type
.
IsValueType
?
OpCodes
.
Call
:
OpCodes
.
Callvirt
,
DefaultTypeMap
.
GetPropertySetter
(
item
.
Property
,
type
));
}
else
{
...
...
@@ -3321,11 +3304,11 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
il
.
Emit
(
OpCodes
.
Pop
);
LoadDefaultValue
(
il
,
item
.
MemberType
);
}
else
if
(
applyNullSetting
&&
(!
memberType
.
IsValueType
()
||
Nullable
.
GetUnderlyingType
(
memberType
)
!=
null
))
else
if
(
applyNullSetting
&&
(!
memberType
.
IsValueType
||
Nullable
.
GetUnderlyingType
(
memberType
)
!=
null
))
{
il
.
Emit
(
OpCodes
.
Pop
);
// stack is now [target][target]
// can load a null with this value
if
(
memberType
.
IsValueType
()
)
if
(
memberType
.
IsValueType
)
{
// must be Nullable<T> for some T
GetTempLocal
(
il
,
ref
structLocals
,
memberType
,
true
);
// stack is now [target][target][null]
}
...
...
@@ -3337,7 +3320,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
// Store the value in the property/field
if
(
item
.
Property
!=
null
)
{
il
.
Emit
(
type
.
IsValueType
()
?
OpCodes
.
Call
:
OpCodes
.
Callvirt
,
DefaultTypeMap
.
GetPropertySetter
(
item
.
Property
,
type
));
il
.
Emit
(
type
.
IsValueType
?
OpCodes
.
Call
:
OpCodes
.
Callvirt
,
DefaultTypeMap
.
GetPropertySetter
(
item
.
Property
,
type
));
// stack is now [target]
}
else
...
...
@@ -3364,7 +3347,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
first
=
false
;
index
++;
}
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
il
.
Emit
(
OpCodes
.
Pop
);
}
...
...
@@ -3375,13 +3358,11 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
il
.
Emit
(
OpCodes
.
Newobj
,
specializedConstructor
);
}
il
.
Emit
(
OpCodes
.
Stloc
,
returnValueLocal
);
// stack is empty
#if !NETSTANDARD1_3
if
(
supportInitialize
)
{
il
.
Emit
(
OpCodes
.
Ldloc
,
returnValueLocal
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
nameof
(
ISupportInitialize
.
EndInit
)),
null
);
}
#endif
}
il
.
MarkLabel
(
allDone
);
il
.
BeginCatchBlock
(
typeof
(
Exception
));
// stack is Exception
...
...
@@ -3392,7 +3373,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
il
.
EndExceptionBlock
();
il
.
Emit
(
OpCodes
.
Ldloc
,
returnValueLocal
);
// stack is [rval]
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
il
.
Emit
(
OpCodes
.
Box
,
type
);
}
...
...
@@ -3401,7 +3382,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
private
static
void
LoadDefaultValue
(
ILGenerator
il
,
Type
type
)
{
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
var
local
=
il
.
DeclareLocal
(
type
);
il
.
Emit
(
OpCodes
.
Ldloca
,
local
);
...
...
@@ -3441,9 +3422,9 @@ private static void LoadReaderValueOrBranchToDBNullLabel(ILGenerator il, int ind
// unbox nullable enums as the primitive, i.e. byte etc
var
nullUnderlyingType
=
Nullable
.
GetUnderlyingType
(
memberType
);
var
unboxType
=
nullUnderlyingType
?.
IsEnum
()
==
true
?
nullUnderlyingType
:
memberType
;
var
unboxType
=
nullUnderlyingType
?.
IsEnum
==
true
?
nullUnderlyingType
:
memberType
;
if
(
unboxType
.
IsEnum
()
)
if
(
unboxType
.
IsEnum
)
{
Type
numericType
=
Enum
.
GetUnderlyingType
(
unboxType
);
if
(
colType
==
typeof
(
string
))
...
...
@@ -3478,9 +3459,9 @@ private static void LoadReaderValueOrBranchToDBNullLabel(ILGenerator il, int ind
}
else
{
TypeCode
dataTypeCode
=
Type
Extensions
.
GetTypeCode
(
colType
),
unboxTypeCode
=
TypeExtensions
.
GetTypeCode
(
unboxType
);
TypeCode
dataTypeCode
=
Type
.
GetTypeCode
(
colType
),
unboxTypeCode
=
Type
.
GetTypeCode
(
unboxType
);
bool
hasTypeHandler
;
if
((
hasTypeHandler
=
typeHandlers
.
ContainsKey
(
unboxType
))
||
colType
==
unboxType
||
dataTypeCode
==
unboxTypeCode
||
dataTypeCode
==
Type
Extensions
.
GetTypeCode
(
nullUnderlyingType
))
if
((
hasTypeHandler
=
typeHandlers
.
ContainsKey
(
unboxType
))
||
colType
==
unboxType
||
dataTypeCode
==
unboxTypeCode
||
dataTypeCode
==
Type
.
GetTypeCode
(
nullUnderlyingType
))
{
if
(
hasTypeHandler
)
{
...
...
@@ -3523,7 +3504,7 @@ private static void FlexibleConvertBoxedFromHeadOfStack(ILGenerator il, Type fro
{
bool
handled
=
false
;
OpCode
opCode
=
default
(
OpCode
);
switch
(
Type
Extensions
.
GetTypeCode
(
from
))
switch
(
Type
.
GetTypeCode
(
from
))
{
case
TypeCode
.
Boolean
:
case
TypeCode
.
Byte
:
...
...
@@ -3537,7 +3518,7 @@ private static void FlexibleConvertBoxedFromHeadOfStack(ILGenerator il, Type fro
case
TypeCode
.
Single
:
case
TypeCode
.
Double
:
handled
=
true
;
switch
(
Type
Extensions
.
GetTypeCode
(
via
??
to
))
switch
(
Type
.
GetTypeCode
(
via
??
to
))
{
case
TypeCode
.
Byte
:
opCode
=
OpCodes
.
Conv_Ovf_I1_Un
;
break
;
...
...
@@ -3635,7 +3616,7 @@ public static void ThrowDataException(Exception ex, int index, IDataReader reade
}
else
{
formattedValue
=
Convert
.
ToString
(
value
)
+
" - "
+
Type
Extensions
.
GetTypeCode
(
value
.
GetType
());
formattedValue
=
Convert
.
ToString
(
value
)
+
" - "
+
Type
.
GetTypeCode
(
value
.
GetType
());
}
}
catch
(
Exception
valEx
)
...
...
@@ -3693,7 +3674,6 @@ public static IEqualityComparer<string> ConnectionStringComparer
private
static
IEqualityComparer
<
string
>
connectionStringComparer
=
StringComparer
.
Ordinal
;
#if !NETSTANDARD1_3
/// <summary>
/// Key used to indicate the type name associated with a DataTable.
/// </summary>
...
...
@@ -3729,7 +3709,6 @@ 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<SqlDataRecord> as a TableValuedParameter.
...
...
@@ -3739,17 +3718,6 @@ public static void SetTypeName(this DataTable table, string typeName)
public
static
ICustomQueryParameter
AsTableValuedParameter
<
T
>(
this
IEnumerable
<
T
>
list
,
string
typeName
=
null
)
where
T
:
IDataRecord
=>
new
SqlDataRecordListTVPParameter
<
T
>(
list
,
typeName
);
/*
/// <summary>
/// Used to pass a IEnumerable<SqlDataRecord> as a TableValuedParameter.
/// </summary>
/// <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<Microsoft.SqlServer.Server.SqlDataRecord>(list, typeName);
// ^^^ retained to avoid missing-method-exception; can presumably drop in a "major"
*/
// one per thread
[
ThreadStatic
]
private
static
StringBuilder
perThreadStringBuilderCache
;
...
...
Dapper/TableValuedParameter.cs
浏览文件 @
8152f2c7
using
System.Data
;
#if !NETSTANDARD1_3
namespace
Dapper
{
/// <summary>
...
...
@@ -49,4 +48,3 @@ internal static void Set(IDbDataParameter parameter, DataTable table, string typ
}
}
}
#endif
Dapper/TypeExtensions.cs
浏览文件 @
8152f2c7
using
System
;
using
System.Reflection
;
using
System.Collections.Generic
;
namespace
Dapper
{
internal
static
class
TypeExtensions
{
public
static
string
Name
(
this
Type
type
)
=>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
Name
;
#else
type
.
Name
;
#endif
public
static
bool
IsValueType
(
this
Type
type
)
=>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
IsValueType
;
#else
type
.
IsValueType
;
#endif
public
static
bool
IsEnum
(
this
Type
type
)
=>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
IsEnum
;
#else
type
.
IsEnum
;
#endif
public
static
bool
IsGenericType
(
this
Type
type
)
=>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
IsGenericType
;
#else
type
.
IsGenericType
;
#endif
public
static
bool
IsInterface
(
this
Type
type
)
=>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
IsInterface
;
#else
type
.
IsInterface
;
#endif
#if NETSTANDARD1_3 || NETCOREAPP1_0
public
static
IEnumerable
<
Attribute
>
GetCustomAttributes
(
this
Type
type
,
bool
inherit
)
{
return
type
.
GetTypeInfo
().
GetCustomAttributes
(
inherit
);
}
public
static
TypeCode
GetTypeCode
(
Type
type
)
{
if
(
type
==
null
)
return
TypeCode
.
Empty
;
if
(
typeCodeLookup
.
TryGetValue
(
type
,
out
TypeCode
result
))
return
result
;
if
(
type
.
IsEnum
())
{
type
=
Enum
.
GetUnderlyingType
(
type
);
if
(
typeCodeLookup
.
TryGetValue
(
type
,
out
result
))
return
result
;
}
return
TypeCode
.
Object
;
}
private
static
readonly
Dictionary
<
Type
,
TypeCode
>
typeCodeLookup
=
new
Dictionary
<
Type
,
TypeCode
>
{
[
typeof
(
bool
)]
=
TypeCode
.
Boolean
,
[
typeof
(
byte
)]
=
TypeCode
.
Byte
,
[
typeof
(
char
)]
=
TypeCode
.
Char
,
[
typeof
(
DateTime
)]
=
TypeCode
.
DateTime
,
[
typeof
(
decimal
)]
=
TypeCode
.
Decimal
,
[
typeof
(
double
)]
=
TypeCode
.
Double
,
[
typeof
(
short
)]
=
TypeCode
.
Int16
,
[
typeof
(
int
)]
=
TypeCode
.
Int32
,
[
typeof
(
long
)]
=
TypeCode
.
Int64
,
[
typeof
(
object
)]
=
TypeCode
.
Object
,
[
typeof
(
sbyte
)]
=
TypeCode
.
SByte
,
[
typeof
(
float
)]
=
TypeCode
.
Single
,
[
typeof
(
string
)]
=
TypeCode
.
String
,
[
typeof
(
ushort
)]
=
TypeCode
.
UInt16
,
[
typeof
(
uint
)]
=
TypeCode
.
UInt32
,
[
typeof
(
ulong
)]
=
TypeCode
.
UInt64
,
};
#else
public
static
TypeCode
GetTypeCode
(
Type
type
)
=>
Type
.
GetTypeCode
(
type
);
#endif
public
static
MethodInfo
GetPublicInstanceMethod
(
this
Type
type
,
string
name
,
Type
[]
types
)
{
#if NETSTANDARD1_3 || NETCOREAPP1_0
var
method
=
type
.
GetMethod
(
name
,
types
);
return
(
method
?.
IsPublic
==
true
&&
!
method
.
IsStatic
)
?
method
:
null
;
#else
return
type
.
GetMethod
(
name
,
BindingFlags
.
Instance
|
BindingFlags
.
Public
,
null
,
types
,
null
);
#endif
}
=>
type
.
GetMethod
(
name
,
BindingFlags
.
Instance
|
BindingFlags
.
Public
,
null
,
types
,
null
);
}
}
Dapper/UdtTypeHandler.cs
浏览文件 @
8152f2c7
...
...
@@ -5,7 +5,6 @@ namespace Dapper
{
public
static
partial
class
SqlMapper
{
#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
...
...
@@ -36,6 +35,5 @@ void ITypeHandler.SetValue(IDbDataParameter parameter, object value)
if
(!(
value
is
DBNull
))
StructuredHelper
.
ConfigureUDT
(
parameter
,
udtTypeName
);
}
}
#endif
}
}
Directory.build.props
浏览文件 @
8152f2c7
...
...
@@ -17,7 +17,7 @@
<DebugType>embedded</DebugType>
<DefaultLanguage>en-US</DefaultLanguage>
<IncludeSymbols>false</IncludeSymbols>
<xUnitVersion>2.4.1
-pre.build.4059
</xUnitVersion>
<xUnitVersion>2.4.1</xUnitVersion>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net451'">
...
...
@@ -25,7 +25,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="
2.2.13
" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning" Version="
3.0.25
" PrivateAssets="all" />
<PackageReference Include="SourceLink.Create.GitHub" Version="2.8.3" PrivateAssets="All" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.8.3" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.8.3" />
...
...
version.json
浏览文件 @
8152f2c7
{
"version"
:
"
1.60
"
,
"assemblyVersion"
:
"
1.6
0.0.0"
,
"version"
:
"
2.0-preview1
"
,
"assemblyVersion"
:
"
2.
0.0.0"
,
"publicReleaseRefSpec"
:
[
"^refs/heads/master$"
,
"^refs/tags/v
\\
d+
\\
.
\\
d+"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录