diff options
author | Atsushi Kanamori <AtsushiKan@users.noreply.github.com> | 2017-09-01 02:13:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-01 02:13:35 +0300 |
commit | 13ea6e4d1b9641f18ab7280bced0674784367766 (patch) | |
tree | e502da70ae3c386fed842a385a5fcb7ebe760d2a /src/System.Private.Reflection.Execution | |
parent | f61d77cf347f921991902274cfdb7eb310b0e641 (diff) |
Implement BindingFlags.DoNotWrapExceptions on Project N (#4437)
This was approved here.
https://github.com/dotnet/corefx/issues/22866
Ok, this one actually makes the feature work. Turned
out not to be too hard.
There are a couple of drive-by items being done here:
- Since the other Invoke overload on MethodInvoker
was only for its use, downgraded its visibility.
- Moved the catch in InvokeUtilites before the finally
that copies back arguments. We don't want to wrap
any exceptions out of the argument post-processing
steps.
Diffstat (limited to 'src/System.Private.Reflection.Execution')
7 files changed, 16 insertions, 16 deletions
diff --git a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/InstanceMethodInvoker.cs b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/InstanceMethodInvoker.cs index 208ca22fe..9bc88142f 100644 --- a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/InstanceMethodInvoker.cs +++ b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/InstanceMethodInvoker.cs @@ -28,7 +28,7 @@ namespace Internal.Reflection.Execution.MethodInvokers } [DebuggerGuidedStepThroughAttribute] - public sealed override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle) + protected sealed override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle, bool wrapInTargetInvocationException) { MethodInvokerUtils.ValidateThis(thisObject, _declaringTypeHandle); object result = RuntimeAugments.CallDynamicInvokeMethod( @@ -40,6 +40,7 @@ namespace Internal.Reflection.Execution.MethodInvokers MethodInvokeInfo.MethodInfo, arguments, binderBundle, + wrapInTargetInvocationException: wrapInTargetInvocationException, invokeMethodHelperIsThisCall: false, methodToCallIsThisCall: true); System.Diagnostics.DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); diff --git a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/IntPtrConstructorMethodInvoker.cs b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/IntPtrConstructorMethodInvoker.cs index 1cbe6ed6c..d5bccc844 100644 --- a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/IntPtrConstructorMethodInvoker.cs +++ b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/IntPtrConstructorMethodInvoker.cs @@ -64,7 +64,7 @@ namespace Internal.Reflection.Execution.MethodInvokers } } - public sealed override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle) + protected sealed override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle, bool wrapInTargetInvocationException) { switch (_id) { @@ -76,7 +76,7 @@ namespace Internal.Reflection.Execution.MethodInvokers { return new IntPtr(value); } - catch (Exception inner) + catch (Exception inner) when (wrapInTargetInvocationException) { throw new TargetInvocationException(inner); } @@ -90,7 +90,7 @@ namespace Internal.Reflection.Execution.MethodInvokers { return new IntPtr(value); } - catch (Exception inner) + catch (Exception inner) when (wrapInTargetInvocationException) { throw new TargetInvocationException(inner); } @@ -104,7 +104,7 @@ namespace Internal.Reflection.Execution.MethodInvokers { return new UIntPtr(value); } - catch (Exception inner) + catch (Exception inner) when (wrapInTargetInvocationException) { throw new TargetInvocationException(inner); } @@ -118,7 +118,7 @@ namespace Internal.Reflection.Execution.MethodInvokers { return new UIntPtr(value); } - catch (Exception inner) + catch (Exception inner) when (wrapInTargetInvocationException) { throw new TargetInvocationException(inner); } diff --git a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/NullableInstanceMethodInvoker.cs b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/NullableInstanceMethodInvoker.cs index 31d817f73..bba2560e1 100644 --- a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/NullableInstanceMethodInvoker.cs +++ b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/NullableInstanceMethodInvoker.cs @@ -83,7 +83,7 @@ namespace Internal.Reflection.Execution.MethodInvokers } } - public sealed override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle) + protected sealed override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle, bool wrapInTargetInvocationException) { Object value = thisObject; bool hasValue = (thisObject != null); diff --git a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/StaticMethodInvoker.cs b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/StaticMethodInvoker.cs index 182e34455..ca348728c 100644 --- a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/StaticMethodInvoker.cs +++ b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/StaticMethodInvoker.cs @@ -25,7 +25,7 @@ namespace Internal.Reflection.Execution.MethodInvokers } [DebuggerGuidedStepThroughAttribute] - public sealed override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle) + protected sealed override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle, bool wrapInTargetInvocationException) { object result = RuntimeAugments.CallDynamicInvokeMethod( thisObject, @@ -36,6 +36,7 @@ namespace Internal.Reflection.Execution.MethodInvokers MethodInvokeInfo.MethodInfo, arguments, binderBundle, + wrapInTargetInvocationException: wrapInTargetInvocationException, invokeMethodHelperIsThisCall: false, methodToCallIsThisCall: false); System.Diagnostics.DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); diff --git a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/StringConstructorMethodInvoker.cs b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/StringConstructorMethodInvoker.cs index 866e624cc..202ccbd92 100644 --- a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/StringConstructorMethodInvoker.cs +++ b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/StringConstructorMethodInvoker.cs @@ -58,7 +58,7 @@ namespace Internal.Reflection.Execution.MethodInvokers } } - public sealed override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle) + protected sealed override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle, bool wrapInTargetInvocationException) { switch (_id) { diff --git a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/SyntheticMethodInvoker.cs b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/SyntheticMethodInvoker.cs index 5409e342f..a1111bb49 100644 --- a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/SyntheticMethodInvoker.cs +++ b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/SyntheticMethodInvoker.cs @@ -27,7 +27,7 @@ namespace Internal.Reflection.Execution.MethodInvokers _parameterTypes = parameterTypes; } - public override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle) + protected sealed override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle, bool wrapInTargetInvocationException) { //@todo: This does not handle optional parameters (nor does it need to as today we're only using it for three synthetic array methods.) if (!(thisObject == null && 0 != (_options & InvokerOptions.AllowNullThis))) @@ -46,12 +46,9 @@ namespace Internal.Reflection.Execution.MethodInvokers { result = _invoker(thisObject, convertedArguments); } - catch (Exception e) + catch (Exception e) when (wrapInTargetInvocationException && ((_options & InvokerOptions.DontWrapException) == 0)) { - if (0 != (_options & InvokerOptions.DontWrapException)) - throw; - else - throw new TargetInvocationException(e); + throw new TargetInvocationException(e); } return result; } diff --git a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/VirtualMethodInvoker.cs b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/VirtualMethodInvoker.cs index c48f2f852..2e7700a04 100644 --- a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/VirtualMethodInvoker.cs +++ b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/VirtualMethodInvoker.cs @@ -52,7 +52,7 @@ namespace Internal.Reflection.Execution.MethodInvokers } [DebuggerGuidedStepThroughAttribute] - public sealed override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle) + protected sealed override Object Invoke(Object thisObject, Object[] arguments, BinderBundle binderBundle, bool wrapInTargetInvocationException) { MethodInvokerUtils.ValidateThis(thisObject, _declaringTypeHandle); @@ -67,6 +67,7 @@ namespace Internal.Reflection.Execution.MethodInvokers MethodInvokeInfo.MethodInfo, arguments, binderBundle, + wrapInTargetInvocationException: wrapInTargetInvocationException, invokeMethodHelperIsThisCall: false, methodToCallIsThisCall: true); System.Diagnostics.DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); |