11using System ;
22using System . Reflection ;
3- using System . Runtime . CompilerServices ;
43using WampSharp . V2 . Client ;
54using WampSharp . CodeGeneration ;
65
@@ -24,28 +23,31 @@ public virtual TProxy GetProxy<TProxy>(ICalleeProxyInterceptor interceptor) wher
2423 return ( TProxy ) Activator . CreateInstance ( typeof ( TProxy ) , mProxy , interceptor ) ;
2524 }
2625
27- if ( ! RuntimeFeature . IsDynamicCodeSupported )
26+ try
2827 {
29- GenerateCodeAndThrowException < TProxy > ( ) ;
30- }
31-
32- TProxy result = DispatchProxy . Create < TProxy , CalleeDispatchProxy > ( ) ;
28+ TProxy result = DispatchProxy . Create < TProxy , CalleeDispatchProxy > ( ) ;
3329
34- CalleeDispatchProxy casted = result as CalleeDispatchProxy ;
30+ CalleeDispatchProxy casted = result as CalleeDispatchProxy ;
3531
36- casted . Handler = mHandler ;
37- casted . CalleeProxyInterceptor = interceptor ;
32+ casted . Handler = mHandler ;
33+ casted . CalleeProxyInterceptor = interceptor ;
3834
39- return result ;
35+ return result ;
36+ }
37+ catch ( NotImplementedException )
38+ {
39+ Exception exception = CreateExceptionWithGeneratedCode < TProxy > ( ) ;
40+ throw exception ;
41+ }
4042 }
4143
42- private static void GenerateCodeAndThrowException < T > ( ) where T : class
44+ private static Exception CreateExceptionWithGeneratedCode < T > ( ) where T : class
4345 {
4446 CalleeProxyCodeGenerator generator = new CalleeProxyCodeGenerator ( typeof ( T ) . Namespace + ".Generated" ) ;
4547
4648 string generatedCode = generator . GenerateCode ( typeof ( T ) ) ;
4749
48- throw new NotSupportedException
50+ return new NotSupportedException
4951 ( "No runtime type code generation available on this platform." +
5052 " You might want to try using GetProxy with the type declared in the inner exception." ,
5153 new GeneratedCodeException ( generatedCode ) ) ;
0 commit comments