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
c340cffd
Commit
c340cffd
authored
May 09, 2011
by
mgravell
Browse files
Options
Browse Files
Download
Plain Diff
Automated merge with
https://dapper-dot-net.googlecode.com/hg/
parents
896ec6da
a24e15c3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
10 deletions
+49
-10
SqlMapper.cs
Dapper/SqlMapper.cs
+19
-10
Tests.cs
Tests/Tests.cs
+30
-0
No files found.
Dapper/SqlMapper.cs
View file @
c340cffd
...
@@ -681,7 +681,7 @@ private static object GetStructDeserializer<T>(IDataReader reader)
...
@@ -681,7 +681,7 @@ private static object GetStructDeserializer<T>(IDataReader reader)
})
})
.
Where
(
info
=>
info
.
Setter
!=
null
)
.
Where
(
info
=>
info
.
Setter
!=
null
)
.
ToList
();
.
ToList
();
var
fields
=
typeof
(
T
).
GetFields
(
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
);
if
(
length
==
-
1
)
if
(
length
==
-
1
)
{
{
length
=
reader
.
FieldCount
-
startBound
;
length
=
reader
.
FieldCount
-
startBound
;
...
@@ -695,9 +695,11 @@ private static object GetStructDeserializer<T>(IDataReader reader)
...
@@ -695,9 +695,11 @@ private static object GetStructDeserializer<T>(IDataReader reader)
var
setters
=
(
var
setters
=
(
from
n
in
names
from
n
in
names
let
prop
=
properties
.
FirstOrDefault
(
p
=>
string
.
Equals
(
p
.
Name
,
n
,
StringComparison
.
InvariantCulture
))
// case sensitive first
let
prop
=
properties
.
FirstOrDefault
(
p
=>
string
.
Equals
(
p
.
Name
,
n
,
StringComparison
.
InvariantCulture
))
// property case sensitive first
??
properties
.
FirstOrDefault
(
p
=>
string
.
Equals
(
p
.
Name
,
n
,
StringComparison
.
InvariantCultureIgnoreCase
))
// case insensitive second
??
properties
.
FirstOrDefault
(
p
=>
string
.
Equals
(
p
.
Name
,
n
,
StringComparison
.
InvariantCultureIgnoreCase
))
// property case insensitive second
select
new
{
Name
=
n
,
Info
=
prop
}
let
field
=
prop
!=
null
?
null
:
(
fields
.
FirstOrDefault
(
p
=>
string
.
Equals
(
p
.
Name
,
n
,
StringComparison
.
InvariantCulture
))
// field case sensitive third
??
fields
.
FirstOrDefault
(
p
=>
string
.
Equals
(
p
.
Name
,
n
,
StringComparison
.
InvariantCultureIgnoreCase
)))
// field case insensitive fourth
select
new
{
Name
=
n
,
Property
=
prop
,
Field
=
field
}
).
ToList
();
).
ToList
();
...
@@ -714,7 +716,7 @@ private static object GetStructDeserializer<T>(IDataReader reader)
...
@@ -714,7 +716,7 @@ private static object GetStructDeserializer<T>(IDataReader reader)
var
@allDone
=
il
.
DefineLabel
();
var
@allDone
=
il
.
DefineLabel
();
foreach
(
var
item
in
setters
)
foreach
(
var
item
in
setters
)
{
{
if
(
item
.
Info
!=
null
)
if
(
item
.
Property
!=
null
||
item
.
Field
!=
null
)
{
{
il
.
Emit
(
OpCodes
.
Dup
);
// stack is now [target][target]
il
.
Emit
(
OpCodes
.
Dup
);
// stack is now [target][target]
Label
isDbNullLabel
=
il
.
DefineLabel
();
Label
isDbNullLabel
=
il
.
DefineLabel
();
...
@@ -731,15 +733,22 @@ private static object GetStructDeserializer<T>(IDataReader reader)
...
@@ -731,15 +733,22 @@ private static object GetStructDeserializer<T>(IDataReader reader)
il
.
Emit
(
OpCodes
.
Brtrue_S
,
isDbNullLabel
);
// stack is now [target][target][value-as-object]
il
.
Emit
(
OpCodes
.
Brtrue_S
,
isDbNullLabel
);
// stack is now [target][target][value-as-object]
// unbox nullable enums as the primitive, i.e. byte etc
// unbox nullable enums as the primitive, i.e. byte etc
var
nullUnderlyingType
=
Nullable
.
GetUnderlyingType
(
item
.
Info
.
Type
);
Type
memberType
=
item
.
Property
!=
null
?
item
.
Property
.
Type
:
item
.
Field
.
FieldType
;
var
unboxType
=
nullUnderlyingType
!=
null
&&
nullUnderlyingType
.
IsEnum
?
nullUnderlyingType
:
item
.
Info
.
Type
;
var
nullUnderlyingType
=
Nullable
.
GetUnderlyingType
(
memberType
);
var
unboxType
=
nullUnderlyingType
!=
null
&&
nullUnderlyingType
.
IsEnum
?
nullUnderlyingType
:
memberType
;
il
.
Emit
(
OpCodes
.
Unbox_Any
,
unboxType
);
// stack is now [target][target][typed-value]
il
.
Emit
(
OpCodes
.
Unbox_Any
,
unboxType
);
// stack is now [target][target][typed-value]
if
(
nullUnderlyingType
!=
null
&&
nullUnderlyingType
.
IsEnum
)
if
(
nullUnderlyingType
!=
null
&&
nullUnderlyingType
.
IsEnum
)
{
{
il
.
Emit
(
OpCodes
.
Newobj
,
item
.
Info
.
Type
.
GetConstructor
(
new
[]
{
nullUnderlyingType
}));
il
.
Emit
(
OpCodes
.
Newobj
,
memberType
.
GetConstructor
(
new
[]
{
nullUnderlyingType
}));
}
if
(
item
.
Property
!=
null
)
{
il
.
Emit
(
OpCodes
.
Callvirt
,
item
.
Property
.
Setter
);
// stack is now [target]
}
else
{
il
.
Emit
(
OpCodes
.
Stfld
,
item
.
Field
);
// stack is now [target]
}
}
il
.
Emit
(
OpCodes
.
Callvirt
,
item
.
Info
.
Setter
);
// stack is now [target]
il
.
Emit
(
OpCodes
.
Br_S
,
finishLabel
);
// stack is now [target]
il
.
Emit
(
OpCodes
.
Br_S
,
finishLabel
);
// stack is now [target]
il
.
MarkLabel
(
isDbNullLabel
);
// incoming stack: [target][target][value]
il
.
MarkLabel
(
isDbNullLabel
);
// incoming stack: [target][target][value]
...
...
Tests/Tests.cs
View file @
c340cffd
...
@@ -322,6 +322,36 @@ public void TestMultiMapDynamic()
...
@@ -322,6 +322,36 @@ public void TestMultiMapDynamic()
connection
.
Execute
(
"drop table #Users drop table #Posts"
);
connection
.
Execute
(
"drop table #Users drop table #Posts"
);
}
}
public
void
TestFieldsAndPrivates
()
{
var
data
=
connection
.
Query
<
TestFieldCaseAndPrivatesEntity
>(
@"select a=1,b=2,c=3,d=4,f='5'"
).
Single
();
data
.
a
.
IsEqualTo
(
1
);
data
.
GetB
().
IsEqualTo
(
2
);
data
.
c
.
IsEqualTo
(
3
);
data
.
GetD
().
IsEqualTo
(
4
);
data
.
e
.
IsEqualTo
(
5
);
}
private
class
TestFieldCaseAndPrivatesEntity
{
public
int
a
{
get
;
set
;
}
private
int
b
{
get
;
set
;
}
public
int
GetB
()
{
return
b
;
}
public
int
c
=
0
;
private
int
d
=
0
;
public
int
GetD
()
{
return
d
;
}
public
int
e
{
get
;
set
;
}
private
string
f
{
get
{
return
e
.
ToString
();
}
set
{
e
=
int
.
Parse
(
value
);
}
}
}
public
void
TestMultiReaderBasic
()
public
void
TestMultiReaderBasic
()
{
{
...
...
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