How to use CreateInstance to retrieve a static member of an assembly?

  • Thread starter Thread starter Dan Mayer
  • Start date Start date
D

Dan Mayer

MyAssembly contains a Type ClassA with a member MyStaticSingletonInstance.

I want to invoke this member to get an instance of the singleton. Maybe
I'm missing something but it seems as though this is not possible! The
reason why is that InvokeMember() requres a target instance. To get that
target instance from MyAssembly.CreateInstance("MyAssembly.ClassA") won't
work because ClassA uses the singleton pattern which has a private ctor.

any thoughts are GREATLY appreciated.

Type type=MyAssembly.GetType("MyAssembly.ClassA");

object target =MyAssembly.CreateInstance("MyAssembly.ClassA");

typeManager.InvokeMember("Instance",BindingFlags.Static,null,target,null);
 
Back
Top