Commit cc4a434 1 parent fc0406a commit cc4a434 Copy full SHA for cc4a434
File tree 3 files changed +37
-2
lines changed
3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -34,4 +34,4 @@ appsettings.config
34
34
.vs /
35
35
# project rider
36
36
.idea
37
-
37
+ .ionide
Original file line number Diff line number Diff line change 3
3
using System . Collections . Generic ;
4
4
using System . Linq ;
5
5
using System . ComponentModel . DataAnnotations ;
6
+ using System . Runtime . ExceptionServices ;
6
7
7
8
namespace Isop . Domain
8
9
{
@@ -23,7 +24,12 @@ public Parameter[] GetParameters(){
23
24
}
24
25
public object Invoke ( object instance , object [ ] values ) {
25
26
if ( instance == null ) throw new ArgumentNullException ( nameof ( instance ) ) ;
26
- return _methodInfo . Invoke ( instance , values ) ;
27
+ try {
28
+ return _methodInfo . Invoke ( instance , values ) ;
29
+ } catch ( TargetInvocationException ex ) {
30
+ ExceptionDispatchInfo . Capture ( ex . InnerException ) . Throw ( ) ;
31
+ return null ;
32
+ }
27
33
}
28
34
29
35
public IEnumerable < Argument > GetArguments ( )
Original file line number Diff line number Diff line change
1
+ using System . Globalization ;
2
+ using System . IO ;
3
+ using System . Linq ;
4
+ using Microsoft . Extensions . DependencyInjection ;
5
+ using NUnit . Framework ;
6
+ namespace Isop . Tests
7
+ {
8
+ [ TestFixture ]
9
+ public class ExceptionsTests
10
+ {
11
+ public class SpecificException : System . Exception
12
+ {
13
+ }
14
+
15
+ [ Test ]
16
+ public void It_can_parse_class_and_method_and_execute ( )
17
+ {
18
+ var sc = new ServiceCollection ( ) ;
19
+ sc . AddSingleton ( ci => new ObjectController ( ) { OnAction = ( ) => throw new SpecificException ( ) } ) ;
20
+
21
+ var arguments = new Build ( sc ) { typeof ( ObjectController ) }
22
+ . SetCulture ( CultureInfo . InvariantCulture )
23
+ . Parse ( new [ ] { "Object" , "Action" } ) ;
24
+
25
+ Assert . That ( arguments . UnRecognizedArguments . Count ( ) , Is . EqualTo ( 0 ) ) ;
26
+ Assert . Throws < SpecificException > ( ( ) => arguments . Invoke ( new StringWriter ( ) ) ) ;
27
+ }
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments