Is there a big performace difference between these 2 sample method calls ?
SampleClass sc = new SampleLib.SampleClass();
sc.DoSomething("Hello");
dynamic dyn = someAssembly.CreateInstance("SampleLib.SampleClass")
dyn.DoSomething("Hello");
Lets assume that
dynamic dyn =
someAssembly.CreateInstance(“SampleLib.SampleClass”)
is not frequent call. Once it creates the instance it will continue intensivly work only with created instance.
The only way to know for sure is to profile in your context. To set expectation,
dynamicis pretty smart, and caches (per pattern) the actual code-path. As such, it is much faster than raw reflection, however an interface should be slightly faster and has the advantage of static checking.Personally, I’d code to an interface from a library dll that both the current code and SampleLib can reference, i.e.