Mykonine

Mykonine

  • NA
  • 520
  • 0

Question on System.Reflection namespace

Jan 30 2005 1:21 PM
I am coding support for plug-ins, and I am doing it via an interface I define from which all classes intended as plugins have to implement. The question I have right now is whether or not this code works... Basically, what I do here is load an assembly from a file, get the types contained and create new instances of NodeRenderer for those that implement I_HwRenderer. The code for the constructor in the NodeRenderer uses Activator.CreateInstance for the given type, and then attempts to cast it to the I_HwRenderer interface. The places where I have my doubts are... 1. Will comparing to that static variable HwR_InterfaceType (bottom of the code block) return true when the type does implement I_HwRenderer? 2. Am I searching the assembly in the right way? 3. Am I allowed to cast the object returned by Activator.CreateInstance to the implemented interface? Thanks in advance. I_HwRenderer instance; public NodeRenderer(Type t) { instance = (I_HwRenderer)(Activator.CreateInstance(t)); } public static NodeRenderer[] FromDll(string dllPath) { ArrayList foundRenderers = new ArrayList(); Assembly nrAssembly = Assembly.LoadFile(dllPath); Type[] types = nrAssembly.GetTypes(); //search for classes in assembly that implement I_HwRenderer for (int i=0; i

Answers (2)