0

I am looking at code that takes an IBar object bar which is really a .net remoting transparent proxy (RuntimeServices.IsTransparentProxy true) and, for a set of IFoo types, does this:

var fooValue = bar as IFoo; // BTW, IFoo is always derived from IBar! But not sure if it matters
if (fooValue != null)
   // and then eventually call some method on IFoo, we can imagine.

Unfortunately this type-casting isn't performing very well, it seems to use a lot of CPU time. What might a better way to do this be? (Unfortunately since it's a transparent proxy you can't do bar.GetType().GetInterfaces()...)

Tim Lovell-Smith
  • 15,310
  • 14
  • 76
  • 93
  • When you say that it doesn't perform well, do you mean that it's slow? Also, you said that bar is a proxy that implements IBar and you said that IFoo is an interface that implements IBar - will the "bar" proxy every actually implement IFoo? – Dan Roberts Jul 01 '16 at 07:27
  • @dan-roberts >...that it's slow? Yes, slow enough/low enough throughput to be a perf bottleneck for this app which is kind of chatty. Yes, *sometimes* the bar proxy does implement IFoo. – Tim Lovell-Smith Jul 11 '16 at 18:06

0 Answers0