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
8d0eb4de
Commit
8d0eb4de
authored
May 02, 2011
by
simon.cropp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avoid some casting by more use of generics
parent
18c01151
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
14 deletions
+10
-14
SqlMapper.cs
Dapper/SqlMapper.cs
+10
-14
No files found.
Dapper/SqlMapper.cs
View file @
8d0eb4de
...
@@ -400,22 +400,22 @@ private static CacheInfo GetCacheInfo(object param, Identity identity)
...
@@ -400,22 +400,22 @@ private static CacheInfo GetCacheInfo(object param, Identity identity)
// dynamic is passed in as Object ... by c# design
// dynamic is passed in as Object ... by c# design
if
(
typeof
(
T
)
==
typeof
(
object
)
||
typeof
(
T
)
==
typeof
(
ExpandoObject
))
if
(
typeof
(
T
)
==
typeof
(
object
)
||
typeof
(
T
)
==
typeof
(
ExpandoObject
))
{
{
oDeserializer
=
GetDynamicDeserializer
(
reader
,
startBound
,
length
,
returnNullIfFirstMissing
);
return
GetDynamicDeserializer
<
T
>
(
reader
,
startBound
,
length
,
returnNullIfFirstMissing
);
}
}
else
if
(
typeof
(
T
).
IsClass
&&
typeof
(
T
)
!=
typeof
(
string
))
else
if
(
typeof
(
T
).
IsClass
&&
typeof
(
T
)
!=
typeof
(
string
))
{
{
oDeserializer
=
GetClassDeserializer
<
T
>(
reader
,
startBound
,
length
,
returnNullIfFirstMissing
:
returnNullIfFirstMissing
);
return
GetClassDeserializer
<
T
>(
reader
,
startBound
,
length
,
returnNullIfFirstMissing
:
returnNullIfFirstMissing
);
}
}
else
else
{
{
oDeserializer
=
GetStructDeserializer
<
T
>(
reader
);
return
GetStructDeserializer
<
T
>(
reader
);
}
}
var
deserializer
=
(
Func
<
IDataReader
,
T
>)
oDeserializer
;
var
deserializer
=
(
Func
<
IDataReader
,
T
>)
oDeserializer
;
return
deserializer
;
return
deserializer
;
}
}
private
static
object
GetDynamicDeserializer
(
IDataRecord
reader
,
int
startBound
=
0
,
int
length
=
-
1
,
bool
returnNullIfFirstMissing
=
false
)
private
static
Func
<
IDataReader
,
T
>
GetDynamicDeserializer
<
T
>
(
IDataRecord
reader
,
int
startBound
=
0
,
int
length
=
-
1
,
bool
returnNullIfFirstMissing
=
false
)
{
{
var
colNames
=
new
List
<
string
>();
var
colNames
=
new
List
<
string
>();
...
@@ -429,7 +429,7 @@ private static object GetDynamicDeserializer(IDataRecord reader, int startBound
...
@@ -429,7 +429,7 @@ private static object GetDynamicDeserializer(IDataRecord reader, int startBound
colNames
.
Add
(
reader
.
GetName
(
i
));
colNames
.
Add
(
reader
.
GetName
(
i
));
}
}
Func
<
IDataReader
,
ExpandoObject
>
rval
=
return
r
=>
r
=>
{
{
IDictionary
<
string
,
object
>
row
=
new
ExpandoObject
();
IDictionary
<
string
,
object
>
row
=
new
ExpandoObject
();
...
@@ -442,15 +442,14 @@ private static object GetDynamicDeserializer(IDataRecord reader, int startBound
...
@@ -442,15 +442,14 @@ private static object GetDynamicDeserializer(IDataRecord reader, int startBound
row
[
colName
]
=
tmp
;
row
[
colName
]
=
tmp
;
if
(
returnNullIfFirstMissing
&&
first
&&
tmp
==
null
)
if
(
returnNullIfFirstMissing
&&
first
&&
tmp
==
null
)
{
{
return
null
;
return
default
(
T
)
;
}
}
i
++;
i
++;
first
=
false
;
first
=
false
;
}
}
return
(
ExpandoObject
)
row
;
return
(
T
)
row
;
};
};
return
rval
;
}
}
[
Browsable
(
false
),
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
Browsable
(
false
),
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
[
Obsolete
(
"This method is for internal usage only"
,
true
)]
[
Obsolete
(
"This method is for internal usage only"
,
true
)]
...
@@ -648,11 +647,9 @@ private static int ExecuteCommand(IDbConnection cnn, IDbTransaction tranaction,
...
@@ -648,11 +647,9 @@ private static int ExecuteCommand(IDbConnection cnn, IDbTransaction tranaction,
}
}
}
}
private
static
object
GetStructDeserializer
<
T
>(
IDataReader
reader
)
private
static
Func
<
IDataReader
,
T
>
GetStructDeserializer
<
T
>(
IDataReader
reader
)
{
{
Func
<
IDataReader
,
T
>
deserializer
=
null
;
return
r
=>
deserializer
=
r
=>
{
{
var
val
=
r
.
GetValue
(
0
);
var
val
=
r
.
GetValue
(
0
);
if
(
val
==
DBNull
.
Value
)
if
(
val
==
DBNull
.
Value
)
...
@@ -661,7 +658,6 @@ private static object GetStructDeserializer<T>(IDataReader reader)
...
@@ -661,7 +658,6 @@ private static object GetStructDeserializer<T>(IDataReader reader)
}
}
return
(
T
)
val
;
return
(
T
)
val
;
};
};
return
deserializer
;
}
}
public
static
Func
<
IDataReader
,
T
>
GetClassDeserializer
<
T
>(
IDataReader
reader
,
int
startBound
=
0
,
int
length
=
-
1
,
bool
returnNullIfFirstMissing
=
false
)
public
static
Func
<
IDataReader
,
T
>
GetClassDeserializer
<
T
>(
IDataReader
reader
,
int
startBound
=
0
,
int
length
=
-
1
,
bool
returnNullIfFirstMissing
=
false
)
...
@@ -796,7 +792,7 @@ public IEnumerable<T> Read<T>()
...
@@ -796,7 +792,7 @@ public IEnumerable<T> Read<T>()
if
(
reader
==
null
)
throw
new
ObjectDisposedException
(
GetType
().
Name
);
if
(
reader
==
null
)
throw
new
ObjectDisposedException
(
GetType
().
Name
);
if
(
consumed
)
throw
new
InvalidOperationException
(
"Each grid can only be iterated once"
);
if
(
consumed
)
throw
new
InvalidOperationException
(
"Each grid can only be iterated once"
);
var
identity
=
new
Identity
(
sql
,
connection
,
typeof
(
T
),
null
);
var
identity
=
new
Identity
(
sql
,
connection
,
typeof
(
T
),
null
);
var
deserializer
=
SqlMapper
.
GetDeserializer
<
T
>(
identity
,
reader
);
var
deserializer
=
GetDeserializer
<
T
>(
identity
,
reader
);
consumed
=
true
;
consumed
=
true
;
return
ReadDeferred
(
gridIndex
,
deserializer
);
return
ReadDeferred
(
gridIndex
,
deserializer
);
}
}
...
...
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