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
6754fe27
Commit
6754fe27
authored
Aug 27, 2019
by
Joseph Musser
Committed by
Marc Gravell
Aug 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ExecuteReaderAsync overloads that return Task<DbDataReader> (#1295)
parent
8b49eb69
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
15 deletions
+96
-15
Extensions.cs
Dapper/Extensions.cs
+44
-0
SqlMapper.Async.cs
Dapper/SqlMapper.Async.cs
+43
-14
WrappedReader.cs
Dapper/WrappedReader.cs
+9
-1
No files found.
Dapper/Extensions.cs
0 → 100644
View file @
6754fe27
using
System
;
using
System.Threading.Tasks
;
namespace
Dapper
{
internal
static
class
Extensions
{
/// <summary>
/// Creates a <see cref="Task{TResult}"/> with a less specific generic parameter that perfectly mirrors the
/// state of the specified <paramref name="task"/>.
/// </summary>
internal
static
Task
<
TTo
>
CastResult
<
TFrom
,
TTo
>(
this
Task
<
TFrom
>
task
)
where
TFrom
:
TTo
{
if
(
task
is
null
)
throw
new
ArgumentNullException
(
nameof
(
task
));
if
(
task
.
Status
==
TaskStatus
.
RanToCompletion
)
return
Task
.
FromResult
((
TTo
)
task
.
Result
);
var
source
=
new
TaskCompletionSource
<
TTo
>();
task
.
ContinueWith
(
OnTaskCompleted
<
TFrom
,
TTo
>,
state
:
source
,
TaskContinuationOptions
.
ExecuteSynchronously
);
return
source
.
Task
;
}
private
static
void
OnTaskCompleted
<
TFrom
,
TTo
>(
Task
<
TFrom
>
completedTask
,
object
state
)
where
TFrom
:
TTo
{
var
source
=
(
TaskCompletionSource
<
TTo
>)
state
;
switch
(
completedTask
.
Status
)
{
case
TaskStatus
.
RanToCompletion
:
source
.
SetResult
(
completedTask
.
Result
);
break
;
case
TaskStatus
.
Canceled
:
source
.
SetCanceled
();
break
;
case
TaskStatus
.
Faulted
:
source
.
SetException
(
completedTask
.
Exception
.
InnerExceptions
);
break
;
}
}
}
}
Dapper/SqlMapper.Async.cs
View file @
6754fe27
This diff is collapsed.
Click to expand it.
Dapper/WrappedReader.cs
View file @
6754fe27
...
...
@@ -93,6 +93,14 @@ public static IDataReader Create(IDbCommand cmd, IDataReader reader)
cmd
.
Dispose
();
return
null
;
// GIGO
}
public
static
DbDataReader
Create
(
IDbCommand
cmd
,
DbDataReader
reader
)
{
if
(
cmd
==
null
)
return
reader
;
// no need to wrap if no command
if
(
reader
!=
null
)
return
new
DbWrappedReader
(
cmd
,
reader
);
cmd
.
Dispose
();
return
null
;
// GIGO
}
}
internal
sealed
class
DbWrappedReader
:
DbDataReader
,
IWrappedDataReader
{
...
...
@@ -143,7 +151,7 @@ protected override void Dispose(bool disposing)
_cmd
=
null
;
}
}
public
override
int
FieldCount
=>
_reader
.
FieldCount
;
public
override
bool
GetBoolean
(
int
i
)
=>
_reader
.
GetBoolean
(
i
);
...
...
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