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
d669d141
Commit
d669d141
authored
Mar 30, 2019
by
mgravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
descriptor API: use index rather than constantly looking up the name
parent
733d1734
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
12 deletions
+24
-12
SqlMapper.DapperRow.Descriptor.cs
Dapper/SqlMapper.DapperRow.Descriptor.cs
+12
-10
SqlMapper.DapperRow.cs
Dapper/SqlMapper.DapperRow.cs
+10
-2
BindingForm.cs
UIBindingTest/BindingForm.cs
+2
-0
No files found.
Dapper/SqlMapper.DapperRow.Descriptor.cs
View file @
d669d141
...
...
@@ -70,7 +70,7 @@ internal static PropertyDescriptorCollection GetProperties(DapperTable table, ID
{
var
type
=
row
!=
null
&&
row
.
TryGetValue
(
names
[
i
],
out
var
value
)
&&
value
!=
null
?
value
.
GetType
()
:
typeof
(
object
);
arr
[
i
]
=
new
RowBoundPropertyDescriptor
(
type
,
names
[
i
]);
arr
[
i
]
=
new
RowBoundPropertyDescriptor
(
type
,
names
[
i
]
,
i
);
}
return
new
PropertyDescriptorCollection
(
arr
,
true
);
}
...
...
@@ -84,20 +84,22 @@ internal static PropertyDescriptorCollection GetProperties(DapperTable table, ID
private
sealed
class
RowBoundPropertyDescriptor
:
PropertyDescriptor
{
private
readonly
Type
_type
;
public
RowBoundPropertyDescriptor
(
Type
type
,
string
name
)
:
base
(
name
,
null
)
=>
_type
=
type
;
public
override
bool
CanResetValue
(
object
component
)
=>
false
;
public
override
void
ResetValue
(
object
component
)
=>
throw
new
NotSupportedException
();
private
readonly
int
_index
;
public
RowBoundPropertyDescriptor
(
Type
type
,
string
name
,
int
index
)
:
base
(
name
,
null
)
{
_type
=
type
;
_index
=
index
;
}
public
override
bool
CanResetValue
(
object
component
)
=>
true
;
public
override
void
ResetValue
(
object
component
)
=>
((
DapperRow
)
component
).
Remove
(
_index
);
public
override
bool
IsReadOnly
=>
false
;
public
override
bool
ShouldSerializeValue
(
object
component
)
=>
true
;
public
override
bool
ShouldSerializeValue
(
object
component
)
=>
((
DapperRow
)
component
).
TryGetValue
(
_index
,
out
_
)
;
public
override
Type
ComponentType
=>
typeof
(
DapperRow
);
public
override
Type
PropertyType
=>
_type
;
public
override
object
GetValue
(
object
component
)
=>
((
IDictionary
<
string
,
object
>)
component
).
TryGetValue
(
Name
,
out
var
val
)
?
val
:
null
;
=>
((
DapperRow
)
component
).
TryGetValue
(
_index
,
out
var
val
)
?
(
val
??
DBNull
.
Value
):
DBNull
.
Value
;
public
override
void
SetValue
(
object
component
,
object
value
)
=>
((
IDictionary
<
string
,
object
>)
component
)[
Name
]
=
value
;
=>
((
DapperRow
)
component
).
SetValue
(
_index
,
value
is
DBNull
?
null
:
value
)
;
}
}
}
...
...
Dapper/SqlMapper.DapperRow.cs
View file @
d669d141
...
...
@@ -40,8 +40,10 @@ private sealed class DeadValue
}
public
bool
TryGetValue
(
string
key
,
out
object
value
)
=>
TryGetValue
(
table
.
IndexOfName
(
key
),
out
value
);
internal
bool
TryGetValue
(
int
index
,
out
object
value
)
{
var
index
=
table
.
IndexOfName
(
key
);
if
(
index
<
0
)
{
// doesn't exist
value
=
null
;
...
...
@@ -146,8 +148,10 @@ IEnumerator IEnumerable.GetEnumerator()
}
bool
IDictionary
<
string
,
object
>.
Remove
(
string
key
)
=>
Remove
(
table
.
IndexOfName
(
key
));
internal
bool
Remove
(
int
index
)
{
int
index
=
table
.
IndexOfName
(
key
);
if
(
index
<
0
||
index
>=
values
.
Length
||
values
[
index
]
is
DeadValue
)
return
false
;
values
[
index
]
=
DeadValue
.
Default
;
return
true
;
...
...
@@ -177,6 +181,10 @@ private object SetValue(string key, object value, bool isAdd)
// then semantically, this value already exists
throw
new
ArgumentException
(
"An item with the same key has already been added"
,
nameof
(
key
));
}
return
SetValue
(
index
,
value
);
}
internal
object
SetValue
(
int
index
,
object
value
)
{
int
oldLength
=
values
.
Length
;
if
(
oldLength
<=
index
)
{
...
...
UIBindingTest/BindingForm.cs
View file @
d669d141
...
...
@@ -10,10 +10,12 @@ public BindingForm()
{
InitializeComponent
();
SuspendLayout
();
using
(
var
conn
=
new
SqlConnection
(
"Data Source=.;Initial Catalog=master;Integrated Security=SSPI"
))
{
mainGrid
.
DataSource
=
conn
.
Query
(
"select * from sys.objects"
).
AsList
();
}
ResumeLayout
();
}
}
}
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