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
c986833d
Commit
c986833d
authored
May 03, 2011
by
mgravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dapper with trace info
parent
973dde61
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
5 deletions
+27
-5
SqlMapper.cs
Dapper/SqlMapper.cs
+27
-5
No files found.
Dapper/SqlMapper.cs
View file @
c986833d
...
...
@@ -677,7 +677,10 @@ private static object GetStructDeserializer<T>(IDataReader reader)
var
dm
=
new
DynamicMethod
(
string
.
Format
(
"Deserialize{0}"
,
Guid
.
NewGuid
()),
typeof
(
T
),
new
[]
{
typeof
(
IDataReader
)
},
true
);
var
il
=
dm
.
GetILGenerator
();
il
.
DeclareLocal
(
typeof
(
int
));
il
.
DeclareLocal
(
typeof
(
T
));
il
.
Emit
(
OpCodes
.
Ldc_I4_0
);
il
.
Emit
(
OpCodes
.
Stloc_0
);
var
properties
=
typeof
(
T
)
.
GetProperties
(
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
)
.
Select
(
p
=>
new
...
...
@@ -714,9 +717,11 @@ private static object GetStructDeserializer<T>(IDataReader reader)
int
index
=
startBound
;
var
@try
=
il
.
BeginExceptionBlock
();
// stack is empty
il
.
Emit
(
OpCodes
.
Newobj
,
typeof
(
T
).
GetConstructor
(
Type
.
EmptyTypes
));
// stack is now [target]
bool
first
=
true
;
var
@allDone
=
il
.
DefineLabel
();
foreach
(
var
item
in
setters
)
{
if
(
item
.
Info
!=
null
)
...
...
@@ -727,7 +732,8 @@ private static object GetStructDeserializer<T>(IDataReader reader)
il
.
Emit
(
OpCodes
.
Ldarg_0
);
// stack is now [target][target][reader]
EmitInt32
(
il
,
index
);
// stack is now [target][target][reader][index]
il
.
Emit
(
OpCodes
.
Dup
);
// stack is now [target][target][reader][index][index]
il
.
Emit
(
OpCodes
.
Stloc_0
);
// stack is now [target][target][reader][index]
il
.
Emit
(
OpCodes
.
Callvirt
,
getItem
);
// stack is now [target][target][value-as-object]
il
.
Emit
(
OpCodes
.
Dup
);
// stack is now [target][target][value][value]
...
...
@@ -747,7 +753,8 @@ private static object GetStructDeserializer<T>(IDataReader reader)
{
il
.
Emit
(
OpCodes
.
Pop
);
il
.
Emit
(
OpCodes
.
Ldnull
);
// stack is now [null]
il
.
Emit
(
OpCodes
.
Ret
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
il
.
Emit
(
OpCodes
.
Br
,
@allDone
);
}
il
.
MarkLabel
(
finishLabel
);
...
...
@@ -755,11 +762,26 @@ private static object GetStructDeserializer<T>(IDataReader reader)
first
=
false
;
index
+=
1
;
}
il
.
Emit
(
OpCodes
.
Ret
);
// stack is empty
il
.
Emit
(
OpCodes
.
Stloc_1
);
// stack is empty
il
.
MarkLabel
(
@allDone
);
il
.
BeginCatchBlock
(
typeof
(
Exception
));
// stack is Exception
il
.
Emit
(
OpCodes
.
Ldloc_0
);
// stack is Exception, index
il
.
Emit
(
OpCodes
.
Ldarg_0
);
// stack is Exception, index, reader
il
.
EmitCall
(
OpCodes
.
Call
,
typeof
(
SqlMapper
).
GetMethod
(
"ThrowDataException"
),
null
);
il
.
Emit
(
OpCodes
.
Ldnull
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
// to make it verifiable
il
.
EndExceptionBlock
();
il
.
Emit
(
OpCodes
.
Ldloc_1
);
// stack is empty
il
.
Emit
(
OpCodes
.
Ret
);
return
(
Func
<
IDataReader
,
T
>)
dm
.
CreateDelegate
(
typeof
(
Func
<
IDataReader
,
T
>));
}
public
static
void
ThrowDataException
(
Exception
ex
,
int
index
,
IDataReader
reader
)
{
string
name
=
reader
!=
null
&&
index
>=
0
&&
index
<
reader
.
FieldCount
?
reader
.
GetName
(
index
)
:
"(n/a)"
;
throw
new
DataException
(
string
.
Format
(
"Error parsing column {0} ({1})"
,
index
,
name
),
ex
);
}
private
static
void
EmitInt32
(
ILGenerator
il
,
int
value
)
{
switch
(
value
)
...
...
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