title: Querying IronPython scripts for interfaces in a hosted environment
body: <p>I'm developing an application written in C# which hosts IronPython. What I'm planning is that the users will write python scripts, which contain classes implementing a pre-defined interface. </p>
  
  <p>Something like:</p>
  
  <p>Define interface in C# code:</p>
  
  <pre><code>public interface IPlugin
  {
      void DoSomething();
  }
  </code></pre>
  
  <p>Implement the interface in python code.</p>
  
  <pre><code>class Plugin(IPlugin):
  
        def DoSomething():
            print "Doing stuff."
  </code></pre>
  
  <p>In my application, I load the python script and execute methods implemented by the classes in those scripts.</p>
  
  <p>I want to know: how do I get a handle to all the classes which implement the specified interface in the python script?</p>
  
  <p>For example: if I were to do the whole thing in C#, I have reflection to help me and I can jut load the assembly and go something like:</p>
  
  <pre><code>    Assembly assembly = Assembly.LoadFrom("plugin.dll");
      Type[] types = assembly.GetTypes();
      foreach(Type type in types)
      {
          foreach(Type interfaceType in type.GetInterface())
          {
              if(interfaceType == typeof(IPlugin))
              {
                  // gotcha, invoke interface specific methods
              }
          }
       }
  </code></pre>
  
  <p>How do I do the same, when instead of an assembly, I'm dealing with an IronPython script? I know that using ObjectOperations and the ScriptScope, I can get a handle to the class, if I know its name -- <a href="http://www.voidspace.org.uk/ironpython/hosting_api.shtml#dynamic-operations" rel="nofollow noreferrer">as described here</a> -- but I'm looking for something more robust.</p>