Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Dapper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
Dapper
Commits
d1b2e154
Commit
d1b2e154
authored
Aug 27, 2019
by
mgravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get rid of all the NS1.3 fallback code
parent
2f7081a3
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
76 additions
and
241 deletions
+76
-241
SqlMapperExtensions.Async.cs
Dapper.Contrib/SqlMapperExtensions.Async.cs
+10
-10
SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+11
-11
Database.cs
Dapper.Rainbow/Database.cs
+1
-1
Snapshotter.cs
Dapper.Rainbow/Snapshotter.cs
+2
-2
Dapper.Tests.Contrib.csproj
Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj
+1
-0
TestSuite.cs
Dapper.Tests.Contrib/TestSuite.cs
+5
-11
TestSuites.cs
Dapper.Tests.Contrib/TestSuites.cs
+2
-5
DataTableHandler.cs
Dapper/DataTableHandler.cs
+0
-2
DefaultTypeMap.cs
Dapper/DefaultTypeMap.cs
+4
-25
DynamicParameters.cs
Dapper/DynamicParameters.cs
+0
-4
SqlDataRecordHandler.cs
Dapper/SqlDataRecordHandler.cs
+0
-2
SqlDataRecordListTVPParameter.cs
Dapper/SqlDataRecordListTVPParameter.cs
+0
-2
SqlMapper.DapperRow.Descriptor.cs
Dapper/SqlMapper.DapperRow.Descriptor.cs
+1
-3
SqlMapper.IDataReader.cs
Dapper/SqlMapper.IDataReader.cs
+1
-1
SqlMapper.TypeHandlerCache.cs
Dapper/SqlMapper.TypeHandlerCache.cs
+0
-2
SqlMapper.cs
Dapper/SqlMapper.cs
+37
-70
TableValuedParameter.cs
Dapper/TableValuedParameter.cs
+0
-2
TypeExtensions.cs
Dapper/TypeExtensions.cs
+1
-86
UdtTypeHandler.cs
Dapper/UdtTypeHandler.cs
+0
-2
No files found.
Dapper.Contrib/SqlMapperExtensions.Async.cs
View file @
d1b2e154
...
@@ -37,7 +37,7 @@ public static partial class SqlMapperExtensions
...
@@ -37,7 +37,7 @@ public static partial class SqlMapperExtensions
var
dynParms
=
new
DynamicParameters
();
var
dynParms
=
new
DynamicParameters
();
dynParms
.
Add
(
"@id"
,
id
);
dynParms
.
Add
(
"@id"
,
id
);
if
(!
type
.
IsInterface
()
)
if
(!
type
.
IsInterface
)
return
(
await
connection
.
QueryAsync
<
T
>(
sql
,
dynParms
,
transaction
,
commandTimeout
).
ConfigureAwait
(
false
)).
FirstOrDefault
();
return
(
await
connection
.
QueryAsync
<
T
>(
sql
,
dynParms
,
transaction
,
commandTimeout
).
ConfigureAwait
(
false
)).
FirstOrDefault
();
var
res
=
(
await
connection
.
QueryAsync
<
dynamic
>(
sql
,
dynParms
).
ConfigureAwait
(
false
)).
FirstOrDefault
()
as
IDictionary
<
string
,
object
>;
var
res
=
(
await
connection
.
QueryAsync
<
dynamic
>(
sql
,
dynParms
).
ConfigureAwait
(
false
)).
FirstOrDefault
()
as
IDictionary
<
string
,
object
>;
...
@@ -51,7 +51,7 @@ public static partial class SqlMapperExtensions
...
@@ -51,7 +51,7 @@ public static partial class SqlMapperExtensions
{
{
var
val
=
res
[
property
.
Name
];
var
val
=
res
[
property
.
Name
];
if
(
val
==
null
)
continue
;
if
(
val
==
null
)
continue
;
if
(
property
.
PropertyType
.
IsGenericType
()
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
if
(
property
.
PropertyType
.
IsGenericType
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
{
{
var
genericType
=
Nullable
.
GetUnderlyingType
(
property
.
PropertyType
);
var
genericType
=
Nullable
.
GetUnderlyingType
(
property
.
PropertyType
);
if
(
genericType
!=
null
)
property
.
SetValue
(
obj
,
Convert
.
ChangeType
(
val
,
genericType
),
null
);
if
(
genericType
!=
null
)
property
.
SetValue
(
obj
,
Convert
.
ChangeType
(
val
,
genericType
),
null
);
...
@@ -92,7 +92,7 @@ public static partial class SqlMapperExtensions
...
@@ -92,7 +92,7 @@ public static partial class SqlMapperExtensions
GetQueries
[
cacheType
.
TypeHandle
]
=
sql
;
GetQueries
[
cacheType
.
TypeHandle
]
=
sql
;
}
}
if
(!
type
.
IsInterface
()
)
if
(!
type
.
IsInterface
)
{
{
return
connection
.
QueryAsync
<
T
>(
sql
,
null
,
transaction
,
commandTimeout
);
return
connection
.
QueryAsync
<
T
>(
sql
,
null
,
transaction
,
commandTimeout
);
}
}
...
@@ -110,7 +110,7 @@ public static partial class SqlMapperExtensions
...
@@ -110,7 +110,7 @@ public static partial class SqlMapperExtensions
{
{
var
val
=
res
[
property
.
Name
];
var
val
=
res
[
property
.
Name
];
if
(
val
==
null
)
continue
;
if
(
val
==
null
)
continue
;
if
(
property
.
PropertyType
.
IsGenericType
()
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
if
(
property
.
PropertyType
.
IsGenericType
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
{
{
var
genericType
=
Nullable
.
GetUnderlyingType
(
property
.
PropertyType
);
var
genericType
=
Nullable
.
GetUnderlyingType
(
property
.
PropertyType
);
if
(
genericType
!=
null
)
property
.
SetValue
(
obj
,
Convert
.
ChangeType
(
val
,
genericType
),
null
);
if
(
genericType
!=
null
)
property
.
SetValue
(
obj
,
Convert
.
ChangeType
(
val
,
genericType
),
null
);
...
@@ -148,11 +148,11 @@ public static partial class SqlMapperExtensions
...
@@ -148,11 +148,11 @@ public static partial class SqlMapperExtensions
isList
=
true
;
isList
=
true
;
type
=
type
.
GetElementType
();
type
=
type
.
GetElementType
();
}
}
else
if
(
type
.
IsGenericType
()
)
else
if
(
type
.
IsGenericType
)
{
{
var
typeInfo
=
type
.
GetTypeInfo
();
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
...
@@ -219,11 +219,11 @@ public static partial class SqlMapperExtensions
...
@@ -219,11 +219,11 @@ public static partial class SqlMapperExtensions
{
{
type
=
type
.
GetElementType
();
type
=
type
.
GetElementType
();
}
}
else
if
(
type
.
IsGenericType
()
)
else
if
(
type
.
IsGenericType
)
{
{
var
typeInfo
=
type
.
GetTypeInfo
();
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
...
@@ -288,11 +288,11 @@ public static partial class SqlMapperExtensions
...
@@ -288,11 +288,11 @@ public static partial class SqlMapperExtensions
{
{
type
=
type
.
GetElementType
();
type
=
type
.
GetElementType
();
}
}
else
if
(
type
.
IsGenericType
()
)
else
if
(
type
.
IsGenericType
)
{
{
var
typeInfo
=
type
.
GetTypeInfo
();
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
...
...
Dapper.Contrib/SqlMapperExtensions.cs
View file @
d1b2e154
...
@@ -190,7 +190,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
...
@@ -190,7 +190,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
T
obj
;
T
obj
;
if
(
type
.
IsInterface
()
)
if
(
type
.
IsInterface
)
{
{
var
res
=
connection
.
Query
(
sql
,
dynParms
).
FirstOrDefault
()
as
IDictionary
<
string
,
object
>;
var
res
=
connection
.
Query
(
sql
,
dynParms
).
FirstOrDefault
()
as
IDictionary
<
string
,
object
>;
...
@@ -203,7 +203,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
...
@@ -203,7 +203,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
{
{
var
val
=
res
[
property
.
Name
];
var
val
=
res
[
property
.
Name
];
if
(
val
==
null
)
continue
;
if
(
val
==
null
)
continue
;
if
(
property
.
PropertyType
.
IsGenericType
()
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
if
(
property
.
PropertyType
.
IsGenericType
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
{
{
var
genericType
=
Nullable
.
GetUnderlyingType
(
property
.
PropertyType
);
var
genericType
=
Nullable
.
GetUnderlyingType
(
property
.
PropertyType
);
if
(
genericType
!=
null
)
property
.
SetValue
(
obj
,
Convert
.
ChangeType
(
val
,
genericType
),
null
);
if
(
genericType
!=
null
)
property
.
SetValue
(
obj
,
Convert
.
ChangeType
(
val
,
genericType
),
null
);
...
@@ -248,7 +248,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
...
@@ -248,7 +248,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
GetQueries
[
cacheType
.
TypeHandle
]
=
sql
;
GetQueries
[
cacheType
.
TypeHandle
]
=
sql
;
}
}
if
(!
type
.
IsInterface
()
)
return
connection
.
Query
<
T
>(
sql
,
null
,
transaction
,
commandTimeout
:
commandTimeout
);
if
(!
type
.
IsInterface
)
return
connection
.
Query
<
T
>(
sql
,
null
,
transaction
,
commandTimeout
:
commandTimeout
);
var
result
=
connection
.
Query
(
sql
);
var
result
=
connection
.
Query
(
sql
);
var
list
=
new
List
<
T
>();
var
list
=
new
List
<
T
>();
...
@@ -259,7 +259,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
...
@@ -259,7 +259,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
{
{
var
val
=
res
[
property
.
Name
];
var
val
=
res
[
property
.
Name
];
if
(
val
==
null
)
continue
;
if
(
val
==
null
)
continue
;
if
(
property
.
PropertyType
.
IsGenericType
()
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
if
(
property
.
PropertyType
.
IsGenericType
&&
property
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>))
{
{
var
genericType
=
Nullable
.
GetUnderlyingType
(
property
.
PropertyType
);
var
genericType
=
Nullable
.
GetUnderlyingType
(
property
.
PropertyType
);
if
(
genericType
!=
null
)
property
.
SetValue
(
obj
,
Convert
.
ChangeType
(
val
,
genericType
),
null
);
if
(
genericType
!=
null
)
property
.
SetValue
(
obj
,
Convert
.
ChangeType
(
val
,
genericType
),
null
);
...
@@ -307,7 +307,7 @@ private static string GetTableName(Type type)
...
@@ -307,7 +307,7 @@ private static string GetTableName(Type type)
else
else
{
{
name
=
type
.
Name
+
"s"
;
name
=
type
.
Name
+
"s"
;
if
(
type
.
IsInterface
()
&&
name
.
StartsWith
(
"I"
))
if
(
type
.
IsInterface
&&
name
.
StartsWith
(
"I"
))
name
=
name
.
Substring
(
1
);
name
=
name
.
Substring
(
1
);
}
}
}
}
...
@@ -336,11 +336,11 @@ private static string GetTableName(Type type)
...
@@ -336,11 +336,11 @@ private static string GetTableName(Type type)
isList
=
true
;
isList
=
true
;
type
=
type
.
GetElementType
();
type
=
type
.
GetElementType
();
}
}
else
if
(
type
.
IsGenericType
()
)
else
if
(
type
.
IsGenericType
)
{
{
var
typeInfo
=
type
.
GetTypeInfo
();
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
...
@@ -417,11 +417,11 @@ private static string GetTableName(Type type)
...
@@ -417,11 +417,11 @@ private static string GetTableName(Type type)
{
{
type
=
type
.
GetElementType
();
type
=
type
.
GetElementType
();
}
}
else
if
(
type
.
IsGenericType
()
)
else
if
(
type
.
IsGenericType
)
{
{
var
typeInfo
=
type
.
GetTypeInfo
();
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
...
@@ -486,11 +486,11 @@ private static string GetTableName(Type type)
...
@@ -486,11 +486,11 @@ private static string GetTableName(Type type)
{
{
type
=
type
.
GetElementType
();
type
=
type
.
GetElementType
();
}
}
else
if
(
type
.
IsGenericType
()
)
else
if
(
type
.
IsGenericType
)
{
{
var
typeInfo
=
type
.
GetTypeInfo
();
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
...
...
Dapper.Rainbow/Database.cs
View file @
d1b2e154
...
@@ -252,7 +252,7 @@ protected Action<TDatabase> CreateTableConstructor(params Type[] tableTypes)
...
@@ -252,7 +252,7 @@ protected Action<TDatabase> CreateTableConstructor(params Type[] tableTypes)
var
il
=
dm
.
GetILGenerator
();
var
il
=
dm
.
GetILGenerator
();
var
setters
=
GetType
().
GetProperties
()
var
setters
=
GetType
().
GetProperties
()
.
Where
(
p
=>
p
.
PropertyType
.
IsGenericType
()
&&
tableTypes
.
Contains
(
p
.
PropertyType
.
GetGenericTypeDefinition
()))
.
Where
(
p
=>
p
.
PropertyType
.
IsGenericType
&&
tableTypes
.
Contains
(
p
.
PropertyType
.
GetGenericTypeDefinition
()))
.
Select
(
p
=>
Tuple
.
Create
(
.
Select
(
p
=>
Tuple
.
Create
(
p
.
GetSetMethod
(
true
),
p
.
GetSetMethod
(
true
),
p
.
PropertyType
.
GetConstructor
(
new
[]
{
typeof
(
TDatabase
),
typeof
(
string
)
}),
p
.
PropertyType
.
GetConstructor
(
new
[]
{
typeof
(
TDatabase
),
typeof
(
string
)
}),
...
...
Dapper.Rainbow/Snapshotter.cs
View file @
d1b2e154
...
@@ -91,8 +91,8 @@ private static List<PropertyInfo> RelevantProperties()
...
@@ -91,8 +91,8 @@ private static List<PropertyInfo> RelevantProperties()
p
.
GetSetMethod
(
true
)
!=
null
p
.
GetSetMethod
(
true
)
!=
null
&&
p
.
GetGetMethod
(
true
)
!=
null
&&
p
.
GetGetMethod
(
true
)
!=
null
&&
(
p
.
PropertyType
==
typeof
(
string
)
&&
(
p
.
PropertyType
==
typeof
(
string
)
||
p
.
PropertyType
.
IsValueType
()
||
p
.
PropertyType
.
IsValueType
||
(
p
.
PropertyType
.
IsGenericType
()
&&
p
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>)))
||
(
p
.
PropertyType
.
IsGenericType
&&
p
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>)))
).
ToList
();
).
ToList
();
}
}
...
...
Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj
View file @
d1b2e154
...
@@ -26,4 +26,5 @@
...
@@ -26,4 +26,5 @@
</PackageReference>
</PackageReference>
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
</ItemGroup>
</ItemGroup>
<!-- note: define SQLCE if SQL CE is available -->
</Project>
</Project>
Dapper.Tests.Contrib/TestSuite.cs
View file @
d1b2e154
...
@@ -2,14 +2,10 @@
...
@@ -2,14 +2,10 @@
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Data
;
using
System.Linq
;
using
System.Linq
;
using
System.Transactions
;
using
Dapper.Contrib.Extensions
;
using
Dapper.Contrib.Extensions
;
using
Xunit
;
using
Xunit
;
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using
System.Transactions
;
using
System.Data.SqlServerCe
;
#endif
using
FactAttribute
=
Dapper
.
Tests
.
Contrib
.
SkippableFactAttribute
;
using
FactAttribute
=
Dapper
.
Tests
.
Contrib
.
SkippableFactAttribute
;
namespace
Dapper.Tests.Contrib
namespace
Dapper.Tests.Contrib
...
@@ -525,7 +521,7 @@ public void InsertGetUpdate()
...
@@ -525,7 +521,7 @@ public void InsertGetUpdate()
}
}
}
}
#if
!NETCOREAPP1_0 && !NETCOREAPP2_0
#if
SQLCE
[
Fact
(
Skip
=
"Not parallel friendly - thinking about how to test this"
)]
[
Fact
(
Skip
=
"Not parallel friendly - thinking about how to test this"
)]
public
void
InsertWithCustomDbType
()
public
void
InsertWithCustomDbType
()
{
{
...
@@ -563,7 +559,7 @@ public void InsertWithCustomTableNameMapper()
...
@@ -563,7 +559,7 @@ public void InsertWithCustomTableNameMapper()
{
{
SqlMapperExtensions
.
TableNameMapper
=
type
=>
SqlMapperExtensions
.
TableNameMapper
=
type
=>
{
{
switch
(
type
.
Name
()
)
switch
(
type
.
Name
)
{
{
case
"Person"
:
case
"Person"
:
return
"People"
;
return
"People"
;
...
@@ -573,7 +569,7 @@ public void InsertWithCustomTableNameMapper()
...
@@ -573,7 +569,7 @@ public void InsertWithCustomTableNameMapper()
return
tableattr
.
Name
;
return
tableattr
.
Name
;
var
name
=
type
.
Name
+
"s"
;
var
name
=
type
.
Name
+
"s"
;
if
(
type
.
IsInterface
()
&&
name
.
StartsWith
(
"I"
))
if
(
type
.
IsInterface
&&
name
.
StartsWith
(
"I"
))
return
name
.
Substring
(
1
);
return
name
.
Substring
(
1
);
return
name
;
return
name
;
}
}
...
@@ -653,7 +649,6 @@ public void Transactions()
...
@@ -653,7 +649,6 @@ public void Transactions()
}
}
}
}
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
[
Fact
]
[
Fact
]
public
void
TransactionScope
()
public
void
TransactionScope
()
{
{
...
@@ -665,11 +660,10 @@ public void TransactionScope()
...
@@ -665,11 +660,10 @@ public void TransactionScope()
txscope
.
Dispose
();
//rollback
txscope
.
Dispose
();
//rollback
Assert
.
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
}
}
}
}
}
}
#endif
[
Fact
]
[
Fact
]
public
void
InsertCheckKey
()
public
void
InsertCheckKey
()
...
...
Dapper.Tests.Contrib/TestSuites.cs
View file @
d1b2e154
...
@@ -7,10 +7,6 @@
...
@@ -7,10 +7,6 @@
using
Xunit
;
using
Xunit
;
using
Xunit.Sdk
;
using
Xunit.Sdk
;
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using
System.Data.SqlServerCe
;
#endif
namespace
Dapper.Tests.Contrib
namespace
Dapper.Tests.Contrib
{
{
// The test suites here implement TestSuiteBase so that each provider runs
// The test suites here implement TestSuiteBase so that each provider runs
...
@@ -148,7 +144,8 @@ static SQLiteTestSuite()
...
@@ -148,7 +144,8 @@ static SQLiteTestSuite()
}
}
}
}
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
#if SQLCE
public
class
SqlCETestSuite
:
TestSuite
public
class
SqlCETestSuite
:
TestSuite
{
{
const
string
FileName
=
"Test.DB.sdf"
;
const
string
FileName
=
"Test.DB.sdf"
;
...
...
Dapper/DataTableHandler.cs
View file @
d1b2e154
using
System
;
using
System
;
using
System.Data
;
using
System.Data
;
#if !NETSTANDARD1_3
namespace
Dapper
namespace
Dapper
{
{
internal
sealed
class
DataTableHandler
:
SqlMapper
.
ITypeHandler
internal
sealed
class
DataTableHandler
:
SqlMapper
.
ITypeHandler
...
@@ -16,4 +15,3 @@ public void SetValue(IDbDataParameter parameter, object value)
...
@@ -16,4 +15,3 @@ public void SetValue(IDbDataParameter parameter, object value)
}
}
}
}
}
}
#
endif
\ No newline at end of file
Dapper/DefaultTypeMap.cs
View file @
d1b2e154
...
@@ -26,27 +26,11 @@ public DefaultTypeMap(Type type)
...
@@ -26,27 +26,11 @@ public DefaultTypeMap(Type type)
Properties
=
GetSettableProps
(
type
);
Properties
=
GetSettableProps
(
type
);
_type
=
type
;
_type
=
type
;
}
}
#if NETSTANDARD1_3
private
static
bool
IsParameterMatch
(
ParameterInfo
[]
x
,
ParameterInfo
[]
y
)
{
if
(
ReferenceEquals
(
x
,
y
))
return
true
;
if
(
x
==
null
||
y
==
null
)
return
false
;
if
(
x
.
Length
!=
y
.
Length
)
return
false
;
for
(
int
i
=
0
;
i
<
x
.
Length
;
i
++)
if
(
x
[
i
].
ParameterType
!=
y
[
i
].
ParameterType
)
return
false
;
return
true
;
}
#endif
internal
static
MethodInfo
GetPropertySetter
(
PropertyInfo
propertyInfo
,
Type
type
)
internal
static
MethodInfo
GetPropertySetter
(
PropertyInfo
propertyInfo
,
Type
type
)
{
{
if
(
propertyInfo
.
DeclaringType
==
type
)
return
propertyInfo
.
GetSetMethod
(
true
);
if
(
propertyInfo
.
DeclaringType
==
type
)
return
propertyInfo
.
GetSetMethod
(
true
);
#if NETSTANDARD1_3
return
propertyInfo
.
DeclaringType
.
GetProperties
(
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
)
.
Single
(
x
=>
x
.
Name
==
propertyInfo
.
Name
&&
x
.
PropertyType
==
propertyInfo
.
PropertyType
&&
IsParameterMatch
(
x
.
GetIndexParameters
(),
propertyInfo
.
GetIndexParameters
())
).
GetSetMethod
(
true
);
#else
return
propertyInfo
.
DeclaringType
.
GetProperty
(
return
propertyInfo
.
DeclaringType
.
GetProperty
(
propertyInfo
.
Name
,
propertyInfo
.
Name
,
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
,
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
,
...
@@ -54,7 +38,6 @@ internal static MethodInfo GetPropertySetter(PropertyInfo propertyInfo, Type typ
...
@@ -54,7 +38,6 @@ internal static MethodInfo GetPropertySetter(PropertyInfo propertyInfo, Type typ
propertyInfo
.
PropertyType
,
propertyInfo
.
PropertyType
,
propertyInfo
.
GetIndexParameters
().
Select
(
p
=>
p
.
ParameterType
).
ToArray
(),
propertyInfo
.
GetIndexParameters
().
Select
(
p
=>
p
.
ParameterType
).
ToArray
(),
null
).
GetSetMethod
(
true
);
null
).
GetSetMethod
(
true
);
#endif
}
}
internal
static
List
<
PropertyInfo
>
GetSettableProps
(
Type
t
)
internal
static
List
<
PropertyInfo
>
GetSettableProps
(
Type
t
)
...
@@ -97,9 +80,9 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
...
@@ -97,9 +80,9 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
continue
;
continue
;
var
unboxedType
=
Nullable
.
GetUnderlyingType
(
ctorParameters
[
i
].
ParameterType
)
??
ctorParameters
[
i
].
ParameterType
;
var
unboxedType
=
Nullable
.
GetUnderlyingType
(
ctorParameters
[
i
].
ParameterType
)
??
ctorParameters
[
i
].
ParameterType
;
if
((
unboxedType
!=
types
[
i
]
&&
!
SqlMapper
.
HasTypeHandler
(
unboxedType
))
if
((
unboxedType
!=
types
[
i
]
&&
!
SqlMapper
.
HasTypeHandler
(
unboxedType
))
&&
!(
unboxedType
.
IsEnum
()
&&
Enum
.
GetUnderlyingType
(
unboxedType
)
==
types
[
i
])
&&
!(
unboxedType
.
IsEnum
&&
Enum
.
GetUnderlyingType
(
unboxedType
)
==
types
[
i
])
&&
!(
unboxedType
==
typeof
(
char
)
&&
types
[
i
]
==
typeof
(
string
))
&&
!(
unboxedType
==
typeof
(
char
)
&&
types
[
i
]
==
typeof
(
string
))
&&
!(
unboxedType
.
IsEnum
()
&&
types
[
i
]
==
typeof
(
string
)))
&&
!(
unboxedType
.
IsEnum
&&
types
[
i
]
==
typeof
(
string
)))
{
{
break
;
break
;
}
}
...
@@ -118,11 +101,7 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
...
@@ -118,11 +101,7 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
public
ConstructorInfo
FindExplicitConstructor
()
public
ConstructorInfo
FindExplicitConstructor
()
{
{
var
constructors
=
_type
.
GetConstructors
(
BindingFlags
.
Instance
|
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
);
var
constructors
=
_type
.
GetConstructors
(
BindingFlags
.
Instance
|
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
);
#if NETSTANDARD1_3
var
withAttr
=
constructors
.
Where
(
c
=>
c
.
CustomAttributes
.
Any
(
x
=>
x
.
AttributeType
==
typeof
(
ExplicitConstructorAttribute
))).
ToList
();
#else
var
withAttr
=
constructors
.
Where
(
c
=>
c
.
GetCustomAttributes
(
typeof
(
ExplicitConstructorAttribute
),
true
).
Length
>
0
).
ToList
();
var
withAttr
=
constructors
.
Where
(
c
=>
c
.
GetCustomAttributes
(
typeof
(
ExplicitConstructorAttribute
),
true
).
Length
>
0
).
ToList
();
#endif
if
(
withAttr
.
Count
==
1
)
if
(
withAttr
.
Count
==
1
)
{
{
...
...
Dapper/DynamicParameters.cs
View file @
d1b2e154
...
@@ -6,10 +6,6 @@
...
@@ -6,10 +6,6 @@
using
System.Reflection
;
using
System.Reflection
;
using
System.Reflection.Emit
;
using
System.Reflection.Emit
;
#if NETSTANDARD1_3
using
ApplicationException
=
System
.
InvalidOperationException
;
#endif
namespace
Dapper
namespace
Dapper
{
{
/// <summary>
/// <summary>
...
...
Dapper/SqlDataRecordHandler.cs
View file @
d1b2e154
...
@@ -5,9 +5,7 @@
...
@@ -5,9 +5,7 @@
namespace
Dapper
namespace
Dapper
{
{
internal
sealed
class
SqlDataRecordHandler
<
T
>
:
SqlMapper
.
ITypeHandler
internal
sealed
class
SqlDataRecordHandler
<
T
>
:
SqlMapper
.
ITypeHandler
#if !NETSTANDARD1_3
where
T
:
IDataRecord
where
T
:
IDataRecord
#endif
{
{
public
object
Parse
(
Type
destinationType
,
object
value
)
public
object
Parse
(
Type
destinationType
,
object
value
)
{
{
...
...
Dapper/SqlDataRecordListTVPParameter.cs
View file @
d1b2e154
...
@@ -12,9 +12,7 @@ namespace Dapper
...
@@ -12,9 +12,7 @@ namespace Dapper
/// Used to pass a IEnumerable<SqlDataRecord> as a SqlDataRecordListTVPParameter
/// Used to pass a IEnumerable<SqlDataRecord> as a SqlDataRecordListTVPParameter
/// </summary>
/// </summary>
internal
sealed
class
SqlDataRecordListTVPParameter
<
T
>
:
SqlMapper
.
ICustomQueryParameter
internal
sealed
class
SqlDataRecordListTVPParameter
<
T
>
:
SqlMapper
.
ICustomQueryParameter
#if !NETSTANDARD1_3
where
T
:
IDataRecord
where
T
:
IDataRecord
#endif
{
{
private
readonly
IEnumerable
<
T
>
data
;
private
readonly
IEnumerable
<
T
>
data
;
private
readonly
string
typeName
;
private
readonly
string
typeName
;
...
...
Dapper/SqlMapper.DapperRow.Descriptor.cs
View file @
d1b2e154
#
if
!
NETSTANDARD1_3
// needs the component-model API
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.ComponentModel
;
...
@@ -104,4 +103,3 @@ public override void SetValue(object component, object value)
...
@@ -104,4 +103,3 @@ public override void SetValue(object component, object value)
}
}
}
}
}
}
#endif
Dapper/SqlMapper.IDataReader.cs
View file @
d1b2e154
...
@@ -140,7 +140,7 @@ public static IEnumerable<dynamic> Parse(this IDataReader reader)
...
@@ -140,7 +140,7 @@ public static IEnumerable<dynamic> Parse(this IDataReader reader)
{
{
concreteType
=
concreteType
??
typeof
(
T
);
concreteType
=
concreteType
??
typeof
(
T
);
var
func
=
GetDeserializer
(
concreteType
,
reader
,
startIndex
,
length
,
returnNullIfFirstMissing
);
var
func
=
GetDeserializer
(
concreteType
,
reader
,
startIndex
,
length
,
returnNullIfFirstMissing
);
if
(
concreteType
.
IsValueType
()
)
if
(
concreteType
.
IsValueType
)
{
{
return
_
=>
(
T
)
func
(
_
);
return
_
=>
(
T
)
func
(
_
);
}
}
...
...
Dapper/SqlMapper.TypeHandlerCache.cs
View file @
d1b2e154
...
@@ -11,9 +11,7 @@ public static partial class SqlMapper
...
@@ -11,9 +11,7 @@ public static partial class SqlMapper
/// </summary>
/// </summary>
/// <typeparam name="T">The type to have a cache for.</typeparam>
/// <typeparam name="T">The type to have a cache for.</typeparam>
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
#if !NETSTANDARD1_3
[
Browsable
(
false
)]
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
public
static
class
TypeHandlerCache
<
T
>
public
static
class
TypeHandlerCache
<
T
>
{
{
...
...
Dapper/SqlMapper.cs
View file @
d1b2e154
...
@@ -12,17 +12,12 @@
...
@@ -12,17 +12,12 @@
using
System.Linq
;
using
System.Linq
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Reflection.Emit
;
using
System.Reflection.Emit
;
using
System.Runtime.CompilerServices
;
using
System.Text
;
using
System.Text
;
using
System.Text.RegularExpressions
;
using
System.Text.RegularExpressions
;
using
System.Threading
;
using
System.Threading
;
using
System.Xml
;
using
System.Xml
;
using
System.Xml.Linq
;
using
System.Xml.Linq
;
#if NETSTANDARD1_3
using
DataException
=
System
.
InvalidOperationException
;
#endif
namespace
Dapper
namespace
Dapper
{
{
/// <summary>
/// <summary>
...
@@ -221,9 +216,7 @@ static SqlMapper()
...
@@ -221,9 +216,7 @@ static SqlMapper()
private
static
void
ResetTypeHandlers
(
bool
clone
)
private
static
void
ResetTypeHandlers
(
bool
clone
)
{
{
typeHandlers
=
new
Dictionary
<
Type
,
ITypeHandler
>();
typeHandlers
=
new
Dictionary
<
Type
,
ITypeHandler
>();
#if !NETSTANDARD1_3
AddTypeHandlerImpl
(
typeof
(
DataTable
),
new
DataTableHandler
(),
clone
);
AddTypeHandlerImpl
(
typeof
(
DataTable
),
new
DataTableHandler
(),
clone
);
#endif
AddTypeHandlerImpl
(
typeof
(
XmlDocument
),
new
XmlDocumentHandler
(),
clone
);
AddTypeHandlerImpl
(
typeof
(
XmlDocument
),
new
XmlDocumentHandler
(),
clone
);
AddTypeHandlerImpl
(
typeof
(
XDocument
),
new
XDocumentHandler
(),
clone
);
AddTypeHandlerImpl
(
typeof
(
XDocument
),
new
XDocumentHandler
(),
clone
);
AddTypeHandlerImpl
(
typeof
(
XElement
),
new
XElementHandler
(),
clone
);
AddTypeHandlerImpl
(
typeof
(
XElement
),
new
XElementHandler
(),
clone
);
...
@@ -281,7 +274,7 @@ public static void AddTypeHandlerImpl(Type type, ITypeHandler handler, bool clon
...
@@ -281,7 +274,7 @@ public static void AddTypeHandlerImpl(Type type, ITypeHandler handler, bool clon
if
(
type
==
null
)
throw
new
ArgumentNullException
(
nameof
(
type
));
if
(
type
==
null
)
throw
new
ArgumentNullException
(
nameof
(
type
));
Type
secondary
=
null
;
Type
secondary
=
null
;
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
{
var
underlying
=
Nullable
.
GetUnderlyingType
(
type
);
var
underlying
=
Nullable
.
GetUnderlyingType
(
type
);
if
(
underlying
==
null
)
if
(
underlying
==
null
)
...
@@ -339,9 +332,7 @@ public static void AddTypeHandlerImpl(Type type, ITypeHandler handler, bool clon
...
@@ -339,9 +332,7 @@ public static void AddTypeHandlerImpl(Type type, ITypeHandler handler, bool clon
/// </summary>
/// </summary>
/// <param name="value">The object to get a corresponding database type for.</param>
/// <param name="value">The object to get a corresponding database type for.</param>
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
#if !NETSTANDARD1_3
[
Browsable
(
false
)]
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
public
static
DbType
GetDbType
(
object
value
)
public
static
DbType
GetDbType
(
object
value
)
{
{
...
@@ -358,16 +349,14 @@ public static DbType GetDbType(object value)
...
@@ -358,16 +349,14 @@ public static DbType GetDbType(object value)
/// <param name="demand">Whether to demand a value (throw if missing).</param>
/// <param name="demand">Whether to demand a value (throw if missing).</param>
/// <param name="handler">The handler for <paramref name="type"/>.</param>
/// <param name="handler">The handler for <paramref name="type"/>.</param>
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
#if !NETSTANDARD1_3
[
Browsable
(
false
)]
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
public
static
DbType
LookupDbType
(
Type
type
,
string
name
,
bool
demand
,
out
ITypeHandler
handler
)
public
static
DbType
LookupDbType
(
Type
type
,
string
name
,
bool
demand
,
out
ITypeHandler
handler
)
{
{
handler
=
null
;
handler
=
null
;
var
nullUnderlyingType
=
Nullable
.
GetUnderlyingType
(
type
);
var
nullUnderlyingType
=
Nullable
.
GetUnderlyingType
(
type
);
if
(
nullUnderlyingType
!=
null
)
type
=
nullUnderlyingType
;
if
(
nullUnderlyingType
!=
null
)
type
=
nullUnderlyingType
;
if
(
type
.
IsEnum
()
&&
!
typeMap
.
ContainsKey
(
type
))
if
(
type
.
IsEnum
&&
!
typeMap
.
ContainsKey
(
type
))
{
{
type
=
Enum
.
GetUnderlyingType
(
type
);
type
=
Enum
.
GetUnderlyingType
(
type
);
}
}
...
@@ -385,7 +374,6 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
...
@@ -385,7 +374,6 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
}
}
if
(
typeof
(
IEnumerable
).
IsAssignableFrom
(
type
))
if
(
typeof
(
IEnumerable
).
IsAssignableFrom
(
type
))
{
{
#if !NETSTANDARD1_3
// auto-detect things like IEnumerable<SqlDataRecord> as a family
// auto-detect things like IEnumerable<SqlDataRecord> as a family
if
(
type
.
IsInterface
&&
type
.
IsGenericType
if
(
type
.
IsInterface
&&
type
.
IsGenericType
&&
type
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>)
&&
type
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>)
...
@@ -407,11 +395,9 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
...
@@ -407,11 +395,9 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
}
}
}
}
}
}
#endif
return
DynamicParameters
.
EnumerableMultiParameter
;
return
DynamicParameters
.
EnumerableMultiParameter
;
}
}
#if !NETSTANDARD1_3 && !NETSTANDARD2_0
switch
(
type
.
FullName
)
switch
(
type
.
FullName
)
{
{
case
"Microsoft.SqlServer.Types.SqlGeography"
:
case
"Microsoft.SqlServer.Types.SqlGeography"
:
...
@@ -424,7 +410,7 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
...
@@ -424,7 +410,7 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
AddTypeHandler
(
type
,
handler
=
new
UdtTypeHandler
(
"hierarchyid"
));
AddTypeHandler
(
type
,
handler
=
new
UdtTypeHandler
(
"hierarchyid"
));
return
DbType
.
Object
;
return
DbType
.
Object
;
}
}
#endif
if
(
demand
)
if
(
demand
)
throw
new
NotSupportedException
(
$"The member
{
name
}
of type
{
type
.
FullName
}
cannot be used as a parameter value"
);
throw
new
NotSupportedException
(
$"The member
{
name
}
of type
{
type
.
FullName
}
cannot be used as a parameter value"
);
return
DbType
.
Object
;
return
DbType
.
Object
;
...
@@ -1787,8 +1773,8 @@ private static void PassByPosition(IDbCommand cmd)
...
@@ -1787,8 +1773,8 @@ private static void PassByPosition(IDbCommand cmd)
return
GetDapperRowDeserializer
(
reader
,
startBound
,
length
,
returnNullIfFirstMissing
);
return
GetDapperRowDeserializer
(
reader
,
startBound
,
length
,
returnNullIfFirstMissing
);
}
}
Type
underlyingType
=
null
;
Type
underlyingType
=
null
;
if
(!(
typeMap
.
ContainsKey
(
type
)
||
type
.
IsEnum
()
||
type
.
FullName
==
LinqBinary
if
(!(
typeMap
.
ContainsKey
(
type
)
||
type
.
IsEnum
||
type
.
FullName
==
LinqBinary
||
(
type
.
IsValueType
()
&&
(
underlyingType
=
Nullable
.
GetUnderlyingType
(
type
))
!=
null
&&
underlyingType
.
IsEnum
()
)))
||
(
type
.
IsValueType
&&
(
underlyingType
=
Nullable
.
GetUnderlyingType
(
type
))
!=
null
&&
underlyingType
.
IsEnum
)))
{
{
if
(
typeHandlers
.
TryGetValue
(
type
,
out
ITypeHandler
handler
))
if
(
typeHandlers
.
TryGetValue
(
type
,
out
ITypeHandler
handler
))
{
{
...
@@ -1880,9 +1866,7 @@ private static Exception MultiMapException(IDataRecord reader)
...
@@ -1880,9 +1866,7 @@ private static Exception MultiMapException(IDataRecord reader)
/// Internal use only.
/// Internal use only.
/// </summary>
/// </summary>
/// <param name="value">The object to convert to a character.</param>
/// <param name="value">The object to convert to a character.</param>
#if !NETSTANDARD1_3
[
Browsable
(
false
)]
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
public
static
char
ReadChar
(
object
value
)
public
static
char
ReadChar
(
object
value
)
...
@@ -1897,9 +1881,7 @@ public static char ReadChar(object value)
...
@@ -1897,9 +1881,7 @@ public static char ReadChar(object value)
/// Internal use only.
/// Internal use only.
/// </summary>
/// </summary>
/// <param name="value">The object to convert to a character.</param>
/// <param name="value">The object to convert to a character.</param>
#if !NETSTANDARD1_3
[
Browsable
(
false
)]
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
public
static
char
?
ReadNullableChar
(
object
value
)
public
static
char
?
ReadNullableChar
(
object
value
)
...
@@ -1916,9 +1898,7 @@ public static char ReadChar(object value)
...
@@ -1916,9 +1898,7 @@ public static char ReadChar(object value)
/// <param name="parameters">The parameter collection to search in.</param>
/// <param name="parameters">The parameter collection to search in.</param>
/// <param name="command">The command for this fetch.</param>
/// <param name="command">The command for this fetch.</param>
/// <param name="name">The name of the parameter to get.</param>
/// <param name="name">The name of the parameter to get.</param>
#if !NETSTANDARD1_3
[
Browsable
(
false
)]
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
true
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
true
)]
public
static
IDbDataParameter
FindOrAddParameter
(
IDataParameterCollection
parameters
,
IDbCommand
command
,
string
name
)
public
static
IDbDataParameter
FindOrAddParameter
(
IDataParameterCollection
parameters
,
IDbCommand
command
,
string
name
)
...
@@ -1974,9 +1954,7 @@ internal static int GetListPaddingExtraCount(int count)
...
@@ -1974,9 +1954,7 @@ internal static int GetListPaddingExtraCount(int count)
/// <param name="command">The command to pack parameters for.</param>
/// <param name="command">The command to pack parameters for.</param>
/// <param name="namePrefix">The name prefix for these parameters.</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>
/// <param name="value">The parameter value can be an <see cref="IEnumerable{T}"/></param>
#if !NETSTANDARD1_3
[
Browsable
(
false
)]
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
public
static
void
PackListParameters
(
IDbCommand
command
,
string
namePrefix
,
object
value
)
public
static
void
PackListParameters
(
IDbCommand
command
,
string
namePrefix
,
object
value
)
...
@@ -2218,7 +2196,7 @@ public static object SanitizeParameterValue(object value)
...
@@ -2218,7 +2196,7 @@ public static object SanitizeParameterValue(object value)
}
}
else
else
{
{
typeCode
=
Type
Extensions
.
GetTypeCode
(
Enum
.
GetUnderlyingType
(
value
.
GetType
()));
typeCode
=
Type
.
GetTypeCode
(
Enum
.
GetUnderlyingType
(
value
.
GetType
()));
}
}
switch
(
typeCode
)
switch
(
typeCode
)
{
{
...
@@ -2277,12 +2255,10 @@ public static string Format(object value)
...
@@ -2277,12 +2255,10 @@ public static string Format(object value)
}
}
else
else
{
{
switch
(
Type
Extensions
.
GetTypeCode
(
value
.
GetType
()))
switch
(
Type
.
GetTypeCode
(
value
.
GetType
()))
{
{
#if !NETSTANDARD1_3
case
TypeCode
.
DBNull
:
case
TypeCode
.
DBNull
:
return
"null"
;
return
"null"
;
#endif
case
TypeCode
.
Boolean
:
case
TypeCode
.
Boolean
:
return
((
bool
)
value
)
?
"1"
:
"0"
;
return
((
bool
)
value
)
?
"1"
:
"0"
;
case
TypeCode
.
Byte
:
case
TypeCode
.
Byte
:
...
@@ -2382,7 +2358,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
...
@@ -2382,7 +2358,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
public
static
Action
<
IDbCommand
,
object
>
CreateParamInfoGenerator
(
Identity
identity
,
bool
checkForDuplicates
,
bool
removeUnused
)
=>
public
static
Action
<
IDbCommand
,
object
>
CreateParamInfoGenerator
(
Identity
identity
,
bool
checkForDuplicates
,
bool
removeUnused
)
=>
CreateParamInfoGenerator
(
identity
,
checkForDuplicates
,
removeUnused
,
GetLiteralTokens
(
identity
.
sql
));
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
)
internal
static
Action
<
IDbCommand
,
object
>
CreateParamInfoGenerator
(
Identity
identity
,
bool
checkForDuplicates
,
bool
removeUnused
,
IList
<
LiteralToken
>
literals
)
{
{
...
@@ -2402,7 +2378,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
...
@@ -2402,7 +2378,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
var
il
=
dm
.
GetILGenerator
();
var
il
=
dm
.
GetILGenerator
();
bool
isStruct
=
type
.
IsValueType
()
;
bool
isStruct
=
type
.
IsValueType
;
bool
haveInt32Arg1
=
false
;
bool
haveInt32Arg1
=
false
;
il
.
Emit
(
OpCodes
.
Ldarg_1
);
// stack is now [untyped-param]
il
.
Emit
(
OpCodes
.
Ldarg_1
);
// stack is now [untyped-param]
if
(
isStruct
)
if
(
isStruct
)
...
@@ -2511,7 +2487,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
...
@@ -2511,7 +2487,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
il
.
Emit
(
OpCodes
.
Ldstr
,
prop
.
Name
);
// stack is now [parameters] [command] [name]
il
.
Emit
(
OpCodes
.
Ldstr
,
prop
.
Name
);
// stack is now [parameters] [command] [name]
il
.
Emit
(
OpCodes
.
Ldloc_0
);
// stack is now [parameters] [command] [name] [typed-param]
il
.
Emit
(
OpCodes
.
Ldloc_0
);
// stack is now [parameters] [command] [name] [typed-param]
il
.
Emit
(
callOpCode
,
prop
.
GetGetMethod
());
// stack is [parameters] [command] [name] [typed-value]
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]
il
.
Emit
(
OpCodes
.
Box
,
prop
.
PropertyType
);
// stack is [parameters] [command] [name] [boxed-value]
}
}
...
@@ -2563,13 +2539,13 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
...
@@ -2563,13 +2539,13 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
il
.
Emit
(
OpCodes
.
Ldloc_0
);
// stack is now [parameters] [[parameters]] [parameter] [parameter] [typed-param]
il
.
Emit
(
OpCodes
.
Ldloc_0
);
// stack is now [parameters] [[parameters]] [parameter] [parameter] [typed-param]
il
.
Emit
(
callOpCode
,
prop
.
GetGetMethod
());
// stack is [parameters] [[parameters]] [parameter] [parameter] [typed-value]
il
.
Emit
(
callOpCode
,
prop
.
GetGetMethod
());
// stack is [parameters] [[parameters]] [parameter] [parameter] [typed-value]
bool
checkForNull
;
bool
checkForNull
;
if
(
prop
.
PropertyType
.
IsValueType
()
)
if
(
prop
.
PropertyType
.
IsValueType
)
{
{
var
propType
=
prop
.
PropertyType
;
var
propType
=
prop
.
PropertyType
;
var
nullType
=
Nullable
.
GetUnderlyingType
(
propType
);
var
nullType
=
Nullable
.
GetUnderlyingType
(
propType
);
bool
callSanitize
=
false
;
bool
callSanitize
=
false
;
if
((
nullType
??
propType
).
IsEnum
()
)
if
((
nullType
??
propType
).
IsEnum
)
{
{
if
(
nullType
!=
null
)
if
(
nullType
!=
null
)
{
{
...
@@ -2581,7 +2557,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
...
@@ -2581,7 +2557,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
{
{
checkForNull
=
false
;
checkForNull
=
false
;
// non-nullable enum; we can do that! just box to the wrong type! (no, really)
// 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
.
Byte
:
propType
=
typeof
(
byte
);
break
;
case
TypeCode
.
SByte
:
propType
=
typeof
(
sbyte
);
break
;
case
TypeCode
.
SByte
:
propType
=
typeof
(
sbyte
);
break
;
...
@@ -2730,7 +2706,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
...
@@ -2730,7 +2706,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
il
.
Emit
(
OpCodes
.
Ldloc_0
);
// command, sql, typed parameter
il
.
Emit
(
OpCodes
.
Ldloc_0
);
// command, sql, typed parameter
il
.
EmitCall
(
callOpCode
,
prop
.
GetGetMethod
(),
null
);
// command, sql, typed value
il
.
EmitCall
(
callOpCode
,
prop
.
GetGetMethod
(),
null
);
// command, sql, typed value
Type
propType
=
prop
.
PropertyType
;
Type
propType
=
prop
.
PropertyType
;
var
typeCode
=
Type
Extensions
.
GetTypeCode
(
propType
);
var
typeCode
=
Type
.
GetTypeCode
(
propType
);
switch
(
typeCode
)
switch
(
typeCode
)
{
{
case
TypeCode
.
Boolean
:
case
TypeCode
.
Boolean
:
...
@@ -2779,7 +2755,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
...
@@ -2779,7 +2755,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
il
.
EmitCall
(
OpCodes
.
Call
,
convert
,
null
);
// command, sql, string value
il
.
EmitCall
(
OpCodes
.
Call
,
convert
,
null
);
// command, sql, string value
break
;
break
;
default
:
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
il
.
EmitCall
(
OpCodes
.
Call
,
format
,
null
);
// command, sql, string value
break
;
break
;
}
}
...
@@ -2797,7 +2773,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
...
@@ -2797,7 +2773,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
{
{
typeof
(
bool
),
typeof
(
sbyte
),
typeof
(
byte
),
typeof
(
ushort
),
typeof
(
short
),
typeof
(
bool
),
typeof
(
sbyte
),
typeof
(
byte
),
typeof
(
ushort
),
typeof
(
short
),
typeof
(
uint
),
typeof
(
int
),
typeof
(
ulong
),
typeof
(
long
),
typeof
(
float
),
typeof
(
double
),
typeof
(
decimal
)
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
)
private
static
MethodInfo
GetToString
(
TypeCode
typeCode
)
{
{
...
@@ -2914,7 +2890,7 @@ private static IDataReader ExecuteReaderImpl(IDbConnection cnn, ref CommandDefin
...
@@ -2914,7 +2890,7 @@ private static IDataReader ExecuteReaderImpl(IDbConnection cnn, ref CommandDefin
}
}
#pragma warning restore 618
#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
{
// assume the value is returned as the correct type (int/byte/etc), but box back to the typed enum
return
r
=>
return
r
=>
{
{
...
@@ -2947,7 +2923,7 @@ private static T Parse<T>(object value)
...
@@ -2947,7 +2923,7 @@ private static T Parse<T>(object value)
if
(
value
is
T
)
return
(
T
)
value
;
if
(
value
is
T
)
return
(
T
)
value
;
var
type
=
typeof
(
T
);
var
type
=
typeof
(
T
);
type
=
Nullable
.
GetUnderlyingType
(
type
)
??
type
;
type
=
Nullable
.
GetUnderlyingType
(
type
)
??
type
;
if
(
type
.
IsEnum
()
)
if
(
type
.
IsEnum
)
{
{
if
(
value
is
float
||
value
is
double
||
value
is
decimal
)
if
(
value
is
float
||
value
is
double
||
value
is
decimal
)
{
{
...
@@ -3080,7 +3056,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
...
@@ -3080,7 +3056,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
throw
MultiMapException
(
reader
);
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
dm
=
new
DynamicMethod
(
"Deserialize"
+
Guid
.
NewGuid
().
ToString
(),
returnType
,
new
[]
{
typeof
(
IDataReader
)
},
type
,
true
);
var
il
=
dm
.
GetILGenerator
();
var
il
=
dm
.
GetILGenerator
();
...
@@ -3202,11 +3178,9 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
...
@@ -3202,11 +3178,9 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
int
index
=
startBound
;
int
index
=
startBound
;
ConstructorInfo
specializedConstructor
=
null
;
ConstructorInfo
specializedConstructor
=
null
;
#if !NETSTANDARD1_3
bool
supportInitialize
=
false
;
bool
supportInitialize
=
false
;
#endif
Dictionary
<
Type
,
LocalBuilder
>
structLocals
=
null
;
Dictionary
<
Type
,
LocalBuilder
>
structLocals
=
null
;
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
{
il
.
Emit
(
OpCodes
.
Ldloca_S
,
(
byte
)
1
);
il
.
Emit
(
OpCodes
.
Ldloca_S
,
(
byte
)
1
);
il
.
Emit
(
OpCodes
.
Initobj
,
type
);
il
.
Emit
(
OpCodes
.
Initobj
,
type
);
...
@@ -3225,7 +3199,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
...
@@ -3225,7 +3199,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
var
consPs
=
explicitConstr
.
GetParameters
();
var
consPs
=
explicitConstr
.
GetParameters
();
foreach
(
var
p
in
consPs
)
foreach
(
var
p
in
consPs
)
{
{
if
(!
p
.
ParameterType
.
IsValueType
()
)
if
(!
p
.
ParameterType
.
IsValueType
)
{
{
il
.
Emit
(
OpCodes
.
Ldnull
);
il
.
Emit
(
OpCodes
.
Ldnull
);
}
}
...
@@ -3237,14 +3211,13 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
...
@@ -3237,14 +3211,13 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
il
.
Emit
(
OpCodes
.
Newobj
,
explicitConstr
);
il
.
Emit
(
OpCodes
.
Newobj
,
explicitConstr
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
#if !NETSTANDARD1_3
supportInitialize
=
typeof
(
ISupportInitialize
).
IsAssignableFrom
(
type
);
supportInitialize
=
typeof
(
ISupportInitialize
).
IsAssignableFrom
(
type
);
if
(
supportInitialize
)
if
(
supportInitialize
)
{
{
il
.
Emit
(
OpCodes
.
Ldloc_1
);
il
.
Emit
(
OpCodes
.
Ldloc_1
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
nameof
(
ISupportInitialize
.
BeginInit
)),
null
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
nameof
(
ISupportInitialize
.
BeginInit
)),
null
);
}
}
#endif
}
}
else
else
{
{
...
@@ -3259,14 +3232,12 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
...
@@ -3259,14 +3232,12 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
{
{
il
.
Emit
(
OpCodes
.
Newobj
,
ctor
);
il
.
Emit
(
OpCodes
.
Newobj
,
ctor
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
#if !NETSTANDARD1_3
supportInitialize
=
typeof
(
ISupportInitialize
).
IsAssignableFrom
(
type
);
supportInitialize
=
typeof
(
ISupportInitialize
).
IsAssignableFrom
(
type
);
if
(
supportInitialize
)
if
(
supportInitialize
)
{
{
il
.
Emit
(
OpCodes
.
Ldloc_1
);
il
.
Emit
(
OpCodes
.
Ldloc_1
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
nameof
(
ISupportInitialize
.
BeginInit
)),
null
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
nameof
(
ISupportInitialize
.
BeginInit
)),
null
);
}
}
#endif
}
}
else
else
{
{
...
@@ -3276,7 +3247,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
...
@@ -3276,7 +3247,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
}
}
il
.
BeginExceptionBlock
();
il
.
BeginExceptionBlock
();
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
{
il
.
Emit
(
OpCodes
.
Ldloca_S
,
(
byte
)
1
);
// [target]
il
.
Emit
(
OpCodes
.
Ldloca_S
,
(
byte
)
1
);
// [target]
}
}
...
@@ -3315,7 +3286,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
...
@@ -3315,7 +3286,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
// Store the value in the property/field
// Store the value in the property/field
if
(
item
.
Property
!=
null
)
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
else
{
{
...
@@ -3331,11 +3302,11 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
...
@@ -3331,11 +3302,11 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
il
.
Emit
(
OpCodes
.
Pop
);
il
.
Emit
(
OpCodes
.
Pop
);
LoadDefaultValue
(
il
,
item
.
MemberType
);
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]
il
.
Emit
(
OpCodes
.
Pop
);
// stack is now [target][target]
// can load a null with this value
// can load a null with this value
if
(
memberType
.
IsValueType
()
)
if
(
memberType
.
IsValueType
)
{
// must be Nullable<T> for some T
{
// must be Nullable<T> for some T
GetTempLocal
(
il
,
ref
structLocals
,
memberType
,
true
);
// stack is now [target][target][null]
GetTempLocal
(
il
,
ref
structLocals
,
memberType
,
true
);
// stack is now [target][target][null]
}
}
...
@@ -3347,7 +3318,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
...
@@ -3347,7 +3318,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
// Store the value in the property/field
// Store the value in the property/field
if
(
item
.
Property
!=
null
)
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]
// stack is now [target]
}
}
else
else
...
@@ -3374,7 +3345,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
...
@@ -3374,7 +3345,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
first
=
false
;
first
=
false
;
index
++;
index
++;
}
}
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
{
il
.
Emit
(
OpCodes
.
Pop
);
il
.
Emit
(
OpCodes
.
Pop
);
}
}
...
@@ -3385,13 +3356,11 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
...
@@ -3385,13 +3356,11 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
il
.
Emit
(
OpCodes
.
Newobj
,
specializedConstructor
);
il
.
Emit
(
OpCodes
.
Newobj
,
specializedConstructor
);
}
}
il
.
Emit
(
OpCodes
.
Stloc_1
);
// stack is empty
il
.
Emit
(
OpCodes
.
Stloc_1
);
// stack is empty
#if !NETSTANDARD1_3
if
(
supportInitialize
)
if
(
supportInitialize
)
{
{
il
.
Emit
(
OpCodes
.
Ldloc_1
);
il
.
Emit
(
OpCodes
.
Ldloc_1
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
nameof
(
ISupportInitialize
.
EndInit
)),
null
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
nameof
(
ISupportInitialize
.
EndInit
)),
null
);
}
}
#endif
}
}
il
.
MarkLabel
(
allDone
);
il
.
MarkLabel
(
allDone
);
il
.
BeginCatchBlock
(
typeof
(
Exception
));
// stack is Exception
il
.
BeginCatchBlock
(
typeof
(
Exception
));
// stack is Exception
...
@@ -3402,7 +3371,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
...
@@ -3402,7 +3371,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
il
.
EndExceptionBlock
();
il
.
EndExceptionBlock
();
il
.
Emit
(
OpCodes
.
Ldloc_1
);
// stack is [rval]
il
.
Emit
(
OpCodes
.
Ldloc_1
);
// stack is [rval]
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
{
il
.
Emit
(
OpCodes
.
Box
,
type
);
il
.
Emit
(
OpCodes
.
Box
,
type
);
}
}
...
@@ -3411,7 +3380,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
...
@@ -3411,7 +3380,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
private
static
void
LoadDefaultValue
(
ILGenerator
il
,
Type
type
)
private
static
void
LoadDefaultValue
(
ILGenerator
il
,
Type
type
)
{
{
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
{
int
localIndex
=
il
.
DeclareLocal
(
type
).
LocalIndex
;
int
localIndex
=
il
.
DeclareLocal
(
type
).
LocalIndex
;
LoadLocalAddress
(
il
,
localIndex
);
LoadLocalAddress
(
il
,
localIndex
);
...
@@ -3451,9 +3420,9 @@ private static void LoadReaderValueOrBranchToDBNullLabel(ILGenerator il, int ind
...
@@ -3451,9 +3420,9 @@ private static void LoadReaderValueOrBranchToDBNullLabel(ILGenerator il, int ind
// unbox nullable enums as the primitive, i.e. byte etc
// unbox nullable enums as the primitive, i.e. byte etc
var
nullUnderlyingType
=
Nullable
.
GetUnderlyingType
(
memberType
);
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
);
Type
numericType
=
Enum
.
GetUnderlyingType
(
unboxType
);
if
(
colType
==
typeof
(
string
))
if
(
colType
==
typeof
(
string
))
...
@@ -3488,9 +3457,9 @@ private static void LoadReaderValueOrBranchToDBNullLabel(ILGenerator il, int ind
...
@@ -3488,9 +3457,9 @@ private static void LoadReaderValueOrBranchToDBNullLabel(ILGenerator il, int ind
}
}
else
else
{
{
TypeCode
dataTypeCode
=
Type
Extensions
.
GetTypeCode
(
colType
),
unboxTypeCode
=
TypeExtensions
.
GetTypeCode
(
unboxType
);
TypeCode
dataTypeCode
=
Type
.
GetTypeCode
(
colType
),
unboxTypeCode
=
Type
.
GetTypeCode
(
unboxType
);
bool
hasTypeHandler
;
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
)
if
(
hasTypeHandler
)
{
{
...
@@ -3533,7 +3502,7 @@ private static void FlexibleConvertBoxedFromHeadOfStack(ILGenerator il, Type fro
...
@@ -3533,7 +3502,7 @@ private static void FlexibleConvertBoxedFromHeadOfStack(ILGenerator il, Type fro
{
{
bool
handled
=
false
;
bool
handled
=
false
;
OpCode
opCode
=
default
(
OpCode
);
OpCode
opCode
=
default
(
OpCode
);
switch
(
Type
Extensions
.
GetTypeCode
(
from
))
switch
(
Type
.
GetTypeCode
(
from
))
{
{
case
TypeCode
.
Boolean
:
case
TypeCode
.
Boolean
:
case
TypeCode
.
Byte
:
case
TypeCode
.
Byte
:
...
@@ -3547,7 +3516,7 @@ private static void FlexibleConvertBoxedFromHeadOfStack(ILGenerator il, Type fro
...
@@ -3547,7 +3516,7 @@ private static void FlexibleConvertBoxedFromHeadOfStack(ILGenerator il, Type fro
case
TypeCode
.
Single
:
case
TypeCode
.
Single
:
case
TypeCode
.
Double
:
case
TypeCode
.
Double
:
handled
=
true
;
handled
=
true
;
switch
(
Type
Extensions
.
GetTypeCode
(
via
??
to
))
switch
(
Type
.
GetTypeCode
(
via
??
to
))
{
{
case
TypeCode
.
Byte
:
case
TypeCode
.
Byte
:
opCode
=
OpCodes
.
Conv_Ovf_I1_Un
;
break
;
opCode
=
OpCodes
.
Conv_Ovf_I1_Un
;
break
;
...
@@ -3703,7 +3672,7 @@ public static void ThrowDataException(Exception ex, int index, IDataReader reade
...
@@ -3703,7 +3672,7 @@ public static void ThrowDataException(Exception ex, int index, IDataReader reade
}
}
else
else
{
{
formattedValue
=
Convert
.
ToString
(
value
)
+
" - "
+
Type
Extensions
.
GetTypeCode
(
value
.
GetType
());
formattedValue
=
Convert
.
ToString
(
value
)
+
" - "
+
Type
.
GetTypeCode
(
value
.
GetType
());
}
}
}
}
catch
(
Exception
valEx
)
catch
(
Exception
valEx
)
...
@@ -3761,7 +3730,6 @@ public static IEqualityComparer<string> ConnectionStringComparer
...
@@ -3761,7 +3730,6 @@ public static IEqualityComparer<string> ConnectionStringComparer
private
static
IEqualityComparer
<
string
>
connectionStringComparer
=
StringComparer
.
Ordinal
;
private
static
IEqualityComparer
<
string
>
connectionStringComparer
=
StringComparer
.
Ordinal
;
#if !NETSTANDARD1_3
/// <summary>
/// <summary>
/// Key used to indicate the type name associated with a DataTable.
/// Key used to indicate the type name associated with a DataTable.
/// </summary>
/// </summary>
...
@@ -3797,7 +3765,6 @@ public static void SetTypeName(this DataTable table, string typeName)
...
@@ -3797,7 +3765,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>
/// <param name="table">The <see cref="DataTable"/> that has a type name associated with it.</param>
public
static
string
GetTypeName
(
this
DataTable
table
)
=>
public
static
string
GetTypeName
(
this
DataTable
table
)
=>
table
?.
ExtendedProperties
[
DataTableTypeNameKey
]
as
string
;
table
?.
ExtendedProperties
[
DataTableTypeNameKey
]
as
string
;
#endif
/// <summary>
/// <summary>
/// Used to pass a IEnumerable<SqlDataRecord> as a TableValuedParameter.
/// Used to pass a IEnumerable<SqlDataRecord> as a TableValuedParameter.
...
...
Dapper/TableValuedParameter.cs
View file @
d1b2e154
using
System.Data
;
using
System.Data
;
#if !NETSTANDARD1_3
namespace
Dapper
namespace
Dapper
{
{
/// <summary>
/// <summary>
...
@@ -49,4 +48,3 @@ internal static void Set(IDbDataParameter parameter, DataTable table, string typ
...
@@ -49,4 +48,3 @@ internal static void Set(IDbDataParameter parameter, DataTable table, string typ
}
}
}
}
}
}
#endif
Dapper/TypeExtensions.cs
View file @
d1b2e154
using
System
;
using
System
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Collections.Generic
;
namespace
Dapper
namespace
Dapper
{
{
internal
static
class
TypeExtensions
internal
static
class
TypeExtensions
{
{
public
static
string
Name
(
this
Type
type
)
=>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
Name
;
#else
type
.
Name
;
#endif
public
static
bool
IsValueType
(
this
Type
type
)
=>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
IsValueType
;
#else
type
.
IsValueType
;
#endif
public
static
bool
IsEnum
(
this
Type
type
)
=>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
IsEnum
;
#else
type
.
IsEnum
;
#endif
public
static
bool
IsGenericType
(
this
Type
type
)
=>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
IsGenericType
;
#else
type
.
IsGenericType
;
#endif
public
static
bool
IsInterface
(
this
Type
type
)
=>
#if NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
IsInterface
;
#else
type
.
IsInterface
;
#endif
#if NETSTANDARD1_3 || NETCOREAPP1_0
public
static
IEnumerable
<
Attribute
>
GetCustomAttributes
(
this
Type
type
,
bool
inherit
)
{
return
type
.
GetTypeInfo
().
GetCustomAttributes
(
inherit
);
}
public
static
TypeCode
GetTypeCode
(
Type
type
)
{
if
(
type
==
null
)
return
TypeCode
.
Empty
;
if
(
typeCodeLookup
.
TryGetValue
(
type
,
out
TypeCode
result
))
return
result
;
if
(
type
.
IsEnum
())
{
type
=
Enum
.
GetUnderlyingType
(
type
);
if
(
typeCodeLookup
.
TryGetValue
(
type
,
out
result
))
return
result
;
}
return
TypeCode
.
Object
;
}
private
static
readonly
Dictionary
<
Type
,
TypeCode
>
typeCodeLookup
=
new
Dictionary
<
Type
,
TypeCode
>
{
[
typeof
(
bool
)]
=
TypeCode
.
Boolean
,
[
typeof
(
byte
)]
=
TypeCode
.
Byte
,
[
typeof
(
char
)]
=
TypeCode
.
Char
,
[
typeof
(
DateTime
)]
=
TypeCode
.
DateTime
,
[
typeof
(
decimal
)]
=
TypeCode
.
Decimal
,
[
typeof
(
double
)]
=
TypeCode
.
Double
,
[
typeof
(
short
)]
=
TypeCode
.
Int16
,
[
typeof
(
int
)]
=
TypeCode
.
Int32
,
[
typeof
(
long
)]
=
TypeCode
.
Int64
,
[
typeof
(
object
)]
=
TypeCode
.
Object
,
[
typeof
(
sbyte
)]
=
TypeCode
.
SByte
,
[
typeof
(
float
)]
=
TypeCode
.
Single
,
[
typeof
(
string
)]
=
TypeCode
.
String
,
[
typeof
(
ushort
)]
=
TypeCode
.
UInt16
,
[
typeof
(
uint
)]
=
TypeCode
.
UInt32
,
[
typeof
(
ulong
)]
=
TypeCode
.
UInt64
,
};
#else
public
static
TypeCode
GetTypeCode
(
Type
type
)
=>
Type
.
GetTypeCode
(
type
);
#endif
public
static
MethodInfo
GetPublicInstanceMethod
(
this
Type
type
,
string
name
,
Type
[]
types
)
public
static
MethodInfo
GetPublicInstanceMethod
(
this
Type
type
,
string
name
,
Type
[]
types
)
{
=>
type
.
GetMethod
(
name
,
BindingFlags
.
Instance
|
BindingFlags
.
Public
,
null
,
types
,
null
);
#if NETSTANDARD1_3 || NETCOREAPP1_0
var
method
=
type
.
GetMethod
(
name
,
types
);
return
(
method
?.
IsPublic
==
true
&&
!
method
.
IsStatic
)
?
method
:
null
;
#else
return
type
.
GetMethod
(
name
,
BindingFlags
.
Instance
|
BindingFlags
.
Public
,
null
,
types
,
null
);
#endif
}
}
}
}
}
Dapper/UdtTypeHandler.cs
View file @
d1b2e154
...
@@ -5,7 +5,6 @@ namespace Dapper
...
@@ -5,7 +5,6 @@ namespace Dapper
{
{
public
static
partial
class
SqlMapper
public
static
partial
class
SqlMapper
{
{
#if !NETSTANDARD1_3 && !NETSTANDARD2_0
/// <summary>
/// <summary>
/// A type handler for data-types that are supported by the underlying provider, but which need
/// A type handler for data-types that are supported by the underlying provider, but which need
/// a well-known UdtTypeName to be specified
/// a well-known UdtTypeName to be specified
...
@@ -36,6 +35,5 @@ void ITypeHandler.SetValue(IDbDataParameter parameter, object value)
...
@@ -36,6 +35,5 @@ void ITypeHandler.SetValue(IDbDataParameter parameter, object value)
if
(!(
value
is
DBNull
))
StructuredHelper
.
ConfigureUDT
(
parameter
,
udtTypeName
);
if
(!(
value
is
DBNull
))
StructuredHelper
.
ConfigureUDT
(
parameter
,
udtTypeName
);
}
}
}
}
#endif
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment