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
42e8f946
Commit
42e8f946
authored
Sep 15, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #168 from StackExchange/fix_detached_head
Fix detached head
parents
b87d9583
863c4c27
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
25 deletions
+27
-25
SqlMapper.cs
Dapper NET40/SqlMapper.cs
+27
-24
Tests.cs
Tests/Tests.cs
+0
-1
No files found.
Dapper NET40/SqlMapper.cs
View file @
42e8f946
...
@@ -4297,14 +4297,20 @@ protected void AddParameters(IDbCommand command, SqlMapper.Identity identity)
...
@@ -4297,14 +4297,20 @@ protected void AddParameters(IDbCommand command, SqlMapper.Identity identity)
}
}
// Now that the parameters are added to the command, let's place our output callbacks
// Now that the parameters are added to the command, let's place our output callbacks
foreach
(
var
generator
in
this
.
outputCallbacks
)
var
tmp
=
outputCallbacks
;
if
(
tmp
!=
null
)
{
foreach
(
var
generator
in
tmp
)
{
{
generator
();
generator
();
}
}
}
}
}
foreach
(
var
param
in
parameters
.
Values
.
Where
(
p
=>
!
p
.
CameFromTemplate
)
)
foreach
(
var
param
in
parameters
.
Values
)
{
{
if
(
param
.
CameFromTemplate
)
continue
;
var
dbType
=
param
.
DbType
;
var
dbType
=
param
.
DbType
;
var
val
=
param
.
Value
;
var
val
=
param
.
Value
;
string
name
=
Clean
(
param
.
Name
);
string
name
=
Clean
(
param
.
Name
);
...
@@ -4480,15 +4486,12 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
...
@@ -4480,15 +4486,12 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
var
dynamicParamName
=
string
.
Join
(
string
.
Empty
,
names
.
ToArray
());
var
dynamicParamName
=
string
.
Join
(
string
.
Empty
,
names
.
ToArray
());
// Before we get all emitty...
// Before we get all emitty...
var
lookup
=
typeof
(
T
).
Name
+
"_"
+
string
.
Join
(
"|"
,
names
.
ToArray
());
var
lookup
=
string
.
Join
(
"|"
,
names
.
ToArray
());
Action
<
object
,
DynamicParameters
>
setter
=
null
;
lock
(
cachedOutputSettersLock
)
var
cache
=
CachedOutputSetters
<
T
>.
Cache
;
{
var
setter
=
(
Action
<
object
,
DynamicParameters
>)
cache
[
lookup
];
if
(
cachedOutputSetters
.
TryGetValue
(
lookup
,
out
setter
))
{
if
(
setter
!=
null
)
goto
MAKECALLBACK
;
goto
MAKECALLBACK
;
}
}
// Come on let's build a method, let's build it, let's build it now!
// Come on let's build a method, let's build it, let's build it now!
var
dm
=
new
DynamicMethod
(
string
.
Format
(
"ExpressionParam{0}"
,
Guid
.
NewGuid
()),
null
,
new
[]
{
typeof
(
object
),
this
.
GetType
()
},
true
);
var
dm
=
new
DynamicMethod
(
string
.
Format
(
"ExpressionParam{0}"
,
Guid
.
NewGuid
()),
null
,
new
[]
{
typeof
(
object
),
this
.
GetType
()
},
true
);
...
@@ -4535,17 +4538,14 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
...
@@ -4535,17 +4538,14 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
il
.
Emit
(
OpCodes
.
Ret
);
// GO
il
.
Emit
(
OpCodes
.
Ret
);
// GO
setter
=
(
Action
<
object
,
DynamicParameters
>)
dm
.
CreateDelegate
(
typeof
(
Action
<
object
,
DynamicParameters
>));
setter
=
(
Action
<
object
,
DynamicParameters
>)
dm
.
CreateDelegate
(
typeof
(
Action
<
object
,
DynamicParameters
>));
lock
(
cachedOutputSettersLock
)
lock
(
cache
)
{
if
(!
cachedOutputSetters
.
ContainsKey
(
lookup
))
{
{
cachedOutputSetters
.
Add
(
lookup
,
setter
);
cache
[
lookup
]
=
setter
;
}
}
}
// Queue the preparation to be fired off when adding parameters to the DbCommand
// Queue the preparation to be fired off when adding parameters to the DbCommand
MAKECALLBACK
:
MAKECALLBACK
:
this
.
outputCallbacks
.
Add
(()
=>
(
outputCallbacks
??
(
outputCallbacks
=
new
List
<
Action
>()))
.
Add
(()
=>
{
{
// Finally, prep the parameter and attach the callback to it
// Finally, prep the parameter and attach the callback to it
ParamInfo
parameter
;
ParamInfo
parameter
;
...
@@ -4579,11 +4579,14 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
...
@@ -4579,11 +4579,14 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
return
this
;
return
this
;
}
}
private
readonly
List
<
Action
>
outputCallbacks
=
new
List
<
Action
>()
;
private
List
<
Action
>
outputCallbacks
;
private
readonly
Dictionary
<
string
,
Action
<
object
,
DynamicParameters
>>
cachedOutputSetters
=
new
Dictionary
<
string
,
Action
<
object
,
DynamicParameters
>>();
private
readonly
Dictionary
<
string
,
Action
<
object
,
DynamicParameters
>>
cachedOutputSetters
=
new
Dictionary
<
string
,
Action
<
object
,
DynamicParameters
>>();
private
readonly
object
cachedOutputSettersLock
=
new
object
();
internal
static
class
CachedOutputSetters
<
T
>
{
public
static
readonly
Hashtable
Cache
=
new
Hashtable
();
}
internal
void
FireOutputCallbacks
()
internal
void
FireOutputCallbacks
()
{
{
...
...
Tests/Tests.cs
View file @
42e8f946
...
@@ -1176,7 +1176,6 @@ public void TestSupportForDynamicParameters()
...
@@ -1176,7 +1176,6 @@ public void TestSupportForDynamicParameters()
p
.
Get
<
int
>(
"age"
).
IsEqualTo
(
11
);
p
.
Get
<
int
>(
"age"
).
IsEqualTo
(
11
);
}
}
[
ActiveTest
]
public
void
TestSupportForDynamicParametersOutputExpressions
()
public
void
TestSupportForDynamicParametersOutputExpressions
()
{
{
var
bob
=
new
Person
{
Name
=
"bob"
,
PersonId
=
1
,
Address
=
new
Address
{
PersonId
=
2
}
};
var
bob
=
new
Person
{
Name
=
"bob"
,
PersonId
=
1
,
Address
=
new
Address
{
PersonId
=
2
}
};
...
...
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