Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJb Evain <jb@evain.net>2018-10-20 01:53:25 +0300
committerMarek Safar <marek.safar@gmail.com>2018-11-02 10:30:11 +0300
commit0e392596cf7b260887866cbee6e1dac36cb954d8 (patch)
treee60904927ec4c273b9877da6ec378052d2d3949e /mcs/class/Mono.Debugger.Soft
parent226a836210c1fc5ed7fc9ddc2fbca538b6711308 (diff)
[Mono.Debugger.Soft] Refactor the InvokeMethodAsync methods to reduce duplication
Diffstat (limited to 'mcs/class/Mono.Debugger.Soft')
-rw-r--r--mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/ObjectMirror.cs49
-rw-r--r--mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/PrimitiveValue.cs11
-rw-r--r--mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/StructMirror.cs32
-rw-r--r--mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/TypeMirror.cs19
4 files changed, 44 insertions, 67 deletions
diff --git a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/ObjectMirror.cs b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/ObjectMirror.cs
index 022cbdceab4..40015eb9671 100644
--- a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/ObjectMirror.cs
+++ b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/ObjectMirror.cs
@@ -164,36 +164,37 @@ namespace Mono.Debugger.Soft
}
public InvokeResult EndInvokeMethodWithResult (IAsyncResult asyncResult) {
- return ObjectMirror.EndInvokeMethodInternalWithResult (asyncResult);
+ return ObjectMirror.EndInvokeMethodInternalWithResult (asyncResult);
}
public Task<Value> InvokeMethodAsync (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options = InvokeOptions.None) {
- var tcs = new TaskCompletionSource<Value> ();
- BeginInvokeMethod (thread, method, arguments, options, iar =>
- {
- try {
- tcs.SetResult (EndInvokeMethod (iar));
- } catch (OperationCanceledException) {
- tcs.TrySetCanceled ();
- } catch (Exception ex) {
- tcs.TrySetException (ex);
- }
- }, null);
- return tcs.Task;
+ return InvokeMethodAsync (vm, thread, method, this, arguments, options);
+ }
+
+ internal static Task<Value> InvokeMethodAsync (VirtualMachine vm, ThreadMirror thread, MethodMirror method, Value this_obj, IList<Value> arguments, InvokeOptions options) {
+ return InvokeMethodAsync (vm, thread, method, this_obj, arguments, options, EndInvokeMethodInternal);
}
public Task<InvokeResult> InvokeMethodAsyncWithResult (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options = InvokeOptions.None) {
- var tcs = new TaskCompletionSource<InvokeResult> ();
- BeginInvokeMethod (thread, method, arguments, options, iar =>
- {
- try {
- tcs.SetResult (EndInvokeMethodInternalWithResult (iar));
- } catch (OperationCanceledException) {
- tcs.TrySetCanceled ();
- } catch (Exception ex) {
- tcs.TrySetException (ex);
- }
- }, null);
+ return InvokeMethodAsyncWithResult (vm, thread, method, this, arguments, options);
+ }
+
+ internal static Task<InvokeResult> InvokeMethodAsyncWithResult (VirtualMachine vm, ThreadMirror thread, MethodMirror method, Value this_obj, IList<Value> arguments, InvokeOptions options) {
+ return InvokeMethodAsync (vm, thread, method, this_obj, arguments, options, EndInvokeMethodInternalWithResult);
+ }
+
+ internal static Task<TResult> InvokeMethodAsync<TResult> (VirtualMachine vm, ThreadMirror thread, MethodMirror method, Value this_obj, IList<Value> arguments, InvokeOptions options, Func<IAsyncResult, TResult> callback) {
+ var tcs = new TaskCompletionSource<TResult> ();
+ BeginInvokeMethod (vm, thread, method, this_obj, arguments, options, iar =>
+ {
+ try {
+ tcs.SetResult (callback (iar));
+ } catch (OperationCanceledException) {
+ tcs.TrySetCanceled ();
+ } catch (Exception ex) {
+ tcs.TrySetException (ex);
+ }
+ }, null);
return tcs.Task;
}
diff --git a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/PrimitiveValue.cs b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/PrimitiveValue.cs
index 2ba50c84d4c..7e99c26faae 100644
--- a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/PrimitiveValue.cs
+++ b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/PrimitiveValue.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Threading.Tasks;
namespace Mono.Debugger.Soft
{
@@ -57,7 +58,15 @@ namespace Mono.Debugger.Soft
}
public InvokeResult EndInvokeMethodWithResult (IAsyncResult asyncResult) {
- return ObjectMirror.EndInvokeMethodInternalWithResult (asyncResult);
+ return ObjectMirror.EndInvokeMethodInternalWithResult (asyncResult);
+ }
+
+ public Task<Value> InvokeMethodAsync (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options = InvokeOptions.None) {
+ return ObjectMirror.InvokeMethodAsync (vm, thread, method, this, arguments, options);
+ }
+
+ public Task<InvokeResult> InvokeMethodAsyncWithResult (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options = InvokeOptions.None) {
+ return ObjectMirror.InvokeMethodAsyncWithResult (vm, thread, method, this, arguments, options);
}
}
} \ No newline at end of file
diff --git a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/StructMirror.cs b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/StructMirror.cs
index f42d9dcb9ea..1744d20f20b 100644
--- a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/StructMirror.cs
+++ b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/StructMirror.cs
@@ -84,11 +84,7 @@ namespace Mono.Debugger.Soft
}
public Value EndInvokeMethod (IAsyncResult asyncResult) {
- var result = ObjectMirror.EndInvokeMethodInternalWithResult (asyncResult);
- var outThis = result.OutThis as StructMirror;
- if (outThis != null) {
- SetFields (outThis.Fields);
- }
+ var result = EndInvokeMethodWithResult (asyncResult);
return result.Result;
}
@@ -102,33 +98,11 @@ namespace Mono.Debugger.Soft
}
public Task<Value> InvokeMethodAsync (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options = InvokeOptions.None) {
- var tcs = new TaskCompletionSource<Value> ();
- BeginInvokeMethod (thread, method, arguments, options, iar =>
- {
- try {
- tcs.SetResult (EndInvokeMethod (iar));
- } catch (OperationCanceledException) {
- tcs.TrySetCanceled ();
- } catch (Exception ex) {
- tcs.TrySetException (ex);
- }
- }, null);
- return tcs.Task;
+ return ObjectMirror.InvokeMethodAsync (vm, thread, method, this, arguments, options, EndInvokeMethod);
}
public Task<InvokeResult> InvokeMethodAsyncWithResult (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options = InvokeOptions.None) {
- var tcs = new TaskCompletionSource<InvokeResult> ();
- BeginInvokeMethod (thread, method, arguments, options, iar =>
- {
- try {
- tcs.SetResult (ObjectMirror.EndInvokeMethodInternalWithResult (iar));
- } catch (OperationCanceledException) {
- tcs.TrySetCanceled ();
- } catch (Exception ex) {
- tcs.TrySetException (ex);
- }
- }, null);
- return tcs.Task;
+ return ObjectMirror.InvokeMethodAsync (vm, thread, method, this, arguments, options, EndInvokeMethodWithResult);
}
}
}
diff --git a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/TypeMirror.cs b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/TypeMirror.cs
index 78c11a8d9af..d59643a501a 100644
--- a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/TypeMirror.cs
+++ b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/TypeMirror.cs
@@ -805,22 +805,15 @@ namespace Mono.Debugger.Soft
}
public InvokeResult EndInvokeMethodWithResult (IAsyncResult asyncResult) {
- return ObjectMirror.EndInvokeMethodInternalWithResult (asyncResult);
+ return ObjectMirror.EndInvokeMethodInternalWithResult (asyncResult);
}
public Task<Value> InvokeMethodAsync (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options = InvokeOptions.None) {
- var tcs = new TaskCompletionSource<Value> ();
- BeginInvokeMethod (thread, method, arguments, options, iar =>
- {
- try {
- tcs.SetResult (EndInvokeMethod (iar));
- } catch (OperationCanceledException) {
- tcs.TrySetCanceled ();
- } catch (Exception ex) {
- tcs.TrySetException (ex);
- }
- }, null);
- return tcs.Task;
+ return ObjectMirror.InvokeMethodAsync (vm, thread, method, null, arguments, options);
+ }
+
+ public Task<InvokeResult> InvokeMethodAsyncWithResult (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options = InvokeOptions.None) {
+ return ObjectMirror.InvokeMethodAsyncWithResult (vm, thread, method, null, arguments, options);
}
public Value NewInstance (ThreadMirror thread, MethodMirror method, IList<Value> arguments) {