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
d2d1adff
Commit
d2d1adff
authored
Feb 23, 2016
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't check for null in the basic enum case
parent
b9288b4a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
5 deletions
+9
-5
SqlMapper.cs
Dapper/SqlMapper.cs
+9
-5
No files found.
Dapper/SqlMapper.cs
View file @
d2d1adff
...
@@ -2295,7 +2295,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
...
@@ -2295,7 +2295,7 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
il
.
Emit
(
OpCodes
.
Dup
);
// stack is now [parameters] [[parameters]] [parameter] [parameter]
il
.
Emit
(
OpCodes
.
Dup
);
// stack is now [parameters] [[parameters]] [parameter] [parameter]
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
=
true
;
bool
checkForNull
;
if
(
prop
.
PropertyType
.
IsValueType
())
if
(
prop
.
PropertyType
.
IsValueType
())
{
{
var
propType
=
prop
.
PropertyType
;
var
propType
=
prop
.
PropertyType
;
...
@@ -2308,10 +2308,11 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
...
@@ -2308,10 +2308,11 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
{
{
// Nullable<SomeEnum>; we want to box as the underlying type; that's just *hard*; for
// Nullable<SomeEnum>; we want to box as the underlying type; that's just *hard*; for
// simplicity, box as Nullable<SomeEnum> and call SanitizeParameterValue
// simplicity, box as Nullable<SomeEnum> and call SanitizeParameterValue
callSanitize
=
true
;
callSanitize
=
checkForNull
=
true
;
}
}
else
else
{
{
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
(
TypeExtensions
.
GetTypeCode
(
Enum
.
GetUnderlyingType
(
propType
)))
switch
(
TypeExtensions
.
GetTypeCode
(
Enum
.
GetUnderlyingType
(
propType
)))
{
{
...
@@ -2326,9 +2327,9 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
...
@@ -2326,9 +2327,9 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
}
}
}
}
}
}
else
if
(
nullType
==
null
)
else
{
// struct but not Nullable<T>; boxed value cannot be null
{
checkForNull
=
false
;
checkForNull
=
nullType
!=
null
;
}
}
il
.
Emit
(
OpCodes
.
Box
,
propType
);
// stack is [parameters] [[parameters]] [parameter] [parameter] [boxed-value]
il
.
Emit
(
OpCodes
.
Box
,
propType
);
// stack is [parameters] [[parameters]] [parameter] [parameter] [boxed-value]
if
(
callSanitize
)
if
(
callSanitize
)
...
@@ -2337,6 +2338,9 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
...
@@ -2337,6 +2338,9 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
il
.
EmitCall
(
OpCodes
.
Call
,
typeof
(
SqlMapper
).
GetMethod
(
nameof
(
SanitizeParameterValue
)),
null
);
il
.
EmitCall
(
OpCodes
.
Call
,
typeof
(
SqlMapper
).
GetMethod
(
nameof
(
SanitizeParameterValue
)),
null
);
// stack is [parameters] [[parameters]] [parameter] [parameter] [boxed-value]
// stack is [parameters] [[parameters]] [parameter] [parameter] [boxed-value]
}
}
}
else
{
checkForNull
=
true
;
// if not a value-type, need to check
}
}
if
(
checkForNull
)
if
(
checkForNull
)
{
{
...
...
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