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
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
View file @
d1b2e154
...
...
@@ -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.Rainbow/Database.cs
View file @
d1b2e154
...
...
@@ -252,7 +252,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
View file @
d1b2e154
...
...
@@ -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
();
}
...
...
Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj
View file @
d1b2e154
...
...
@@ -26,4 +26,5 @@
</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
View file @
d1b2e154
...
...
@@ -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
;
}
...
...
@@ -653,7 +649,6 @@ public void Transactions()
}
}
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
[
Fact
]
public
void
TransactionScope
()
{
...
...
@@ -665,11 +660,10 @@ 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
}
}
}
#endif
[
Fact
]
public
void
InsertCheckKey
()
...
...
Dapper.Tests.Contrib/TestSuites.cs
View file @
d1b2e154
...
...
@@ -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
...
...
@@ -148,7 +144,8 @@ static SQLiteTestSuite()
}
}
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
#if SQLCE
public
class
SqlCETestSuite
:
TestSuite
{
const
string
FileName
=
"Test.DB.sdf"
;
...
...
Dapper/DataTableHandler.cs
View file @
d1b2e154
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
View file @
d1b2e154
...
...
@@ -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
View file @
d1b2e154
...
...
@@ -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
View file @
d1b2e154
...
...
@@ -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
View file @
d1b2e154
...
...
@@ -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.DapperRow.Descriptor.cs
View file @
d1b2e154
#
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.IDataReader.cs
View file @
d1b2e154
...
...
@@ -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.TypeHandlerCache.cs
View file @
d1b2e154
...
...
@@ -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
View file @
d1b2e154
...
...
@@ -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,9 +216,7 @@ static SqlMapper()
private
static
void
ResetTypeHandlers
(
bool
clone
)
{
typeHandlers
=
new
Dictionary
<
Type
,
ITypeHandler
>();
#if !NETSTANDARD1_3
AddTypeHandlerImpl
(
typeof
(
DataTable
),
new
DataTableHandler
(),
clone
);
#endif
AddTypeHandlerImpl
(
typeof
(
XmlDocument
),
new
XmlDocumentHandler
(),
clone
);
AddTypeHandlerImpl
(
typeof
(
XDocument
),
new
XDocumentHandler
(),
clone
);
AddTypeHandlerImpl
(
typeof
(
XElement
),
new
XElementHandler
(),
clone
);
...
...
@@ -281,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
)
...
...
@@ -339,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
)
{
...
...
@@ -358,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
);
}
...
...
@@ -385,7 +374,6 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
}
if
(
typeof
(
IEnumerable
).
IsAssignableFrom
(
type
))
{
#if !NETSTANDARD1_3
// auto-detect things like IEnumerable<SqlDataRecord> as a family
if
(
type
.
IsInterface
&&
type
.
IsGenericType
&&
type
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>)
...
...
@@ -407,11 +395,9 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
}
}
}
#endif
return
DynamicParameters
.
EnumerableMultiParameter
;
}
#if !NETSTANDARD1_3 && !NETSTANDARD2_0
switch
(
type
.
FullName
)
{
case
"Microsoft.SqlServer.Types.SqlGeography"
:
...
...
@@ -424,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
;
...
...
@@ -1787,8 +1773,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
))
{
...
...
@@ -1880,9 +1866,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
)
...
...
@@ -1897,9 +1881,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
)
...
...
@@ -1916,9 +1898,7 @@ public static char ReadChar(object value)
/// <param name="parameters">The parameter collection to search in.</param>
/// <param name="command">The command for this fetch.</param>
/// <param name="name">The name of the parameter to get.</param>
#if !NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
Obsolete
(
ObsoleteInternalUsageOnly
,
true
)]
public
static
IDbDataParameter
FindOrAddParameter
(
IDataParameterCollection
parameters
,
IDbCommand
command
,
string
name
)
...
...
@@ -1974,9 +1954,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
)
...
...
@@ -2218,7 +2196,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
)
{
...
...
@@ -2277,12 +2255,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
:
...
...
@@ -2382,7 +2358,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
)
{
...
...
@@ -2402,7 +2378,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
var
il
=
dm
.
GetILGenerator
();
bool
isStruct
=
type
.
IsValueType
()
;
bool
isStruct
=
type
.
IsValueType
;
bool
haveInt32Arg1
=
false
;
il
.
Emit
(
OpCodes
.
Ldarg_1
);
// stack is now [untyped-param]
if
(
isStruct
)
...
...
@@ -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
.
Ldloc_0
);
// 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]
}
...
...
@@ -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
(
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
)
{
...
...
@@ -2581,7 +2557,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
;
...
...
@@ -2730,7 +2706,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
il
.
Emit
(
OpCodes
.
Ldloc_0
);
// 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
:
...
...
@@ -2779,7 +2755,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
;
}
...
...
@@ -2797,7 +2773,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
)
{
...
...
@@ -2914,7 +2890,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
=>
{
...
...
@@ -2947,7 +2923,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
)
{
...
...
@@ -3080,7 +3056,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
();
...
...
@@ -3202,11 +3178,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_S
,
(
byte
)
1
);
il
.
Emit
(
OpCodes
.
Initobj
,
type
);
...
...
@@ -3225,7 +3199,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
);
}
...
...
@@ -3237,14 +3211,13 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
il
.
Emit
(
OpCodes
.
Newobj
,
explicitConstr
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
#if !NETSTANDARD1_3
supportInitialize
=
typeof
(
ISupportInitialize
).
IsAssignableFrom
(
type
);
if
(
supportInitialize
)
{
il
.
Emit
(
OpCodes
.
Ldloc_1
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
nameof
(
ISupportInitialize
.
BeginInit
)),
null
);
}
#endif
}
else
{
...
...
@@ -3259,14 +3232,12 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
{
il
.
Emit
(
OpCodes
.
Newobj
,
ctor
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
#if !NETSTANDARD1_3
supportInitialize
=
typeof
(
ISupportInitialize
).
IsAssignableFrom
(
type
);
if
(
supportInitialize
)
{
il
.
Emit
(
OpCodes
.
Ldloc_1
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
nameof
(
ISupportInitialize
.
BeginInit
)),
null
);
}
#endif
}
else
{
...
...
@@ -3276,7 +3247,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
}
il
.
BeginExceptionBlock
();
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
il
.
Emit
(
OpCodes
.
Ldloca_S
,
(
byte
)
1
);
// [target]
}
...
...
@@ -3315,7 +3286,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
{
...
...
@@ -3331,11 +3302,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]
}
...
...
@@ -3347,7 +3318,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
...
...
@@ -3374,7 +3345,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
first
=
false
;
index
++;
}
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
il
.
Emit
(
OpCodes
.
Pop
);
}
...
...
@@ -3385,13 +3356,11 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
il
.
Emit
(
OpCodes
.
Newobj
,
specializedConstructor
);
}
il
.
Emit
(
OpCodes
.
Stloc_1
);
// stack is empty
#if !NETSTANDARD1_3
if
(
supportInitialize
)
{
il
.
Emit
(
OpCodes
.
Ldloc_1
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
typeof
(
ISupportInitialize
).
GetMethod
(
nameof
(
ISupportInitialize
.
EndInit
)),
null
);
}
#endif
}
il
.
MarkLabel
(
allDone
);
il
.
BeginCatchBlock
(
typeof
(
Exception
));
// stack is Exception
...
...
@@ -3402,7 +3371,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
il
.
EndExceptionBlock
();
il
.
Emit
(
OpCodes
.
Ldloc_1
);
// stack is [rval]
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
il
.
Emit
(
OpCodes
.
Box
,
type
);
}
...
...
@@ -3411,7 +3380,7 @@ private static void GenerateDeserializerFromMap(Type type, IDataReader reader, i
private
static
void
LoadDefaultValue
(
ILGenerator
il
,
Type
type
)
{
if
(
type
.
IsValueType
()
)
if
(
type
.
IsValueType
)
{
int
localIndex
=
il
.
DeclareLocal
(
type
).
LocalIndex
;
LoadLocalAddress
(
il
,
localIndex
);
...
...
@@ -3451,9 +3420,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
))
...
...
@@ -3488,9 +3457,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
)
{
...
...
@@ -3533,7 +3502,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
:
...
...
@@ -3547,7 +3516,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
;
...
...
@@ -3703,7 +3672,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
)
...
...
@@ -3761,7 +3730,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>
...
...
@@ -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>
public
static
string
GetTypeName
(
this
DataTable
table
)
=>
table
?.
ExtendedProperties
[
DataTableTypeNameKey
]
as
string
;
#endif
/// <summary>
/// Used to pass a IEnumerable<SqlDataRecord> as a TableValuedParameter.
...
...
Dapper/TableValuedParameter.cs
View file @
d1b2e154
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
View file @
d1b2e154
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
View file @
d1b2e154
...
...
@@ -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
}
}
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