Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* move AsyncHelpers to Bindings folder * Only call bindings with AsyncHelpers when they are actually async (return Task) * extract synchronous binding invocation to a service, to be able to customize it more easily
- Loading branch information
1 parent
99557a6
commit f3ee016
Showing
7 changed files
with
70 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
TechTalk.SpecFlow/Bindings/SynchronousBindingDelegateInvoker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace TechTalk.SpecFlow.Bindings | ||
{ | ||
public interface ISynchronousBindingDelegateInvoker | ||
{ | ||
object InvokeDelegateSynchronously(Delegate bindingDelegate, object[] invokeArgs); | ||
} | ||
|
||
public class SynchronousBindingDelegateInvoker : ISynchronousBindingDelegateInvoker | ||
{ | ||
public virtual object InvokeDelegateSynchronously(Delegate bindingDelegate, object[] invokeArgs) | ||
{ | ||
if (typeof(Task).IsAssignableFrom(bindingDelegate.Method.ReturnType)) | ||
return InvokeBindingDelegateAsync(bindingDelegate, invokeArgs); | ||
return InvokeBindingDelegateSync(bindingDelegate, invokeArgs); | ||
} | ||
|
||
protected virtual object InvokeBindingDelegateSync(Delegate bindingDelegate, object[] invokeArgs) | ||
{ | ||
return bindingDelegate.DynamicInvoke(invokeArgs); | ||
} | ||
|
||
protected virtual object InvokeBindingDelegateAsync(Delegate bindingDelegate, object[] invokeArgs) | ||
{ | ||
return AsyncHelpers.RunSync(async () => | ||
{ | ||
var r = bindingDelegate.DynamicInvoke(invokeArgs); | ||
if (r is Task t) | ||
await t; | ||
return r; | ||
}); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters