Guest User

Untitled

a guest
Feb 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. private Dictionary<string, Applet> loadApplets(string path)
  2. {
  3. Dictionary<string, Applet> applets = new Dictionary<string, Applet>();
  4. string[] files = Directory.GetFiles(path, "*.dll");
  5.  
  6. foreach (string file in files)
  7. {
  8. try
  9. {
  10. Assembly a = Assembly.LoadFile(file);
  11. Type[] types = a.GetTypes();
  12. foreach (Type type in types)
  13. {
  14. if (type.GetInterface("IAppletPlugin") != null)
  15. {
  16. object[] attribs = type.GetCustomAttributes(
  17. typeof(AppletInformationAttribute), false);
  18. if (attribs.Length == 1)
  19. {
  20. System.Diagnostics.Debug.Print("Applet loaded");
  21. AppletInformationAttribute aia = (AppletInformationAttribute)attribs[0];
  22. Applet applet = new Applet(
  23. aia.AppletName,
  24. aia.AppletDescription,
  25. (IAppletPlugin)Activator.CreateInstance(type));
  26. applets.Add(aia.AppletName, applet);
  27. }
  28. }
  29. }
  30. }
  31. catch (Exception e)
  32. {
  33. System.Diagnostics.Debug.Print(e.Message);
  34. }
  35. }
  36. return applets;
  37. }
Add Comment
Please, Sign In to add comment