Skip to content

Commit 1f1560d

Browse files
committed
Generating code when NotImplementedException is caught
1 parent 47698b0 commit 1f1560d

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/netstandard/WampSharp/WAMP2/V2/Api/CalleeProxy/WampCalleeClientProxyFactory.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Reflection;
3-
using System.Runtime.CompilerServices;
43
using WampSharp.V2.Client;
54
using 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

Comments
 (0)