FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
January 01, 2003

Implementing a Plug-In Architecture in C#

(Page 6 of 6)
January 2003/Implementing a Plug-In Architecture with C#

Listing 4: The method LoadPlugs

private void LoadPlugs()
{
  string[] files = Directory.GetFiles("Plugs", "*.plug");

  foreach(string f in files)
  {

    try
    {
      Assembly a = Assembly.LoadFrom(f);
      System.Type[] types = a.GetTypes();
      foreach(System.Type type in types)
      {
        if(type.GetInterface("IPlug")!=null)
        {
          if(type.GetCustomAttributes(typeof(PlugDisplayNameAttribute),
  false).Length!=1)
            throw new PlugNotValidException(type,
              "PlugDisplayNameAttribute is not supported");
          if(type.GetCustomAttributes(typeof(PlugDescriptionAttribute),
  false).Length!=1)
            throw new PlugNotValidException(type, 
              "PlugDescriptionAttribute is not supported");

          _tree.Nodes.Add(new PlugTreeNode(type));
        }
      }
    }
    catch(Exception e)

    {
      MessageBox.Show(e.Message);
    }
  }

  return;
}
Previous Page | 1 | 2 | 3 | 4 | 5 | 6
RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK