终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

38 lines
953 B

  1. using BPASmartClient.Helper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace BPASmartClient.Business
  8. {
  9. public class Plugin : Singleton<Plugin>, IDisposable
  10. {
  11. private List<IPlugin> plugins = new List<IPlugin>();
  12. public void Dispose()
  13. {
  14. plugins.ForEach(p => p.Dispose());
  15. }
  16. public void Init()
  17. {
  18. this.GetType().Assembly.GetTypes().ToList().ForEach(plugin =>
  19. {
  20. if (plugin.GetInterfaces().Contains(typeof(IPlugin)))
  21. {
  22. plugins.Add((IPlugin)Activator.CreateInstance(plugin));
  23. }
  24. });
  25. plugins.ForEach(p => p.Initialize());
  26. }
  27. public T GetPlugin<T>() where T : IPlugin
  28. {
  29. return (T)plugins.FirstOrDefault(p => p.GetType().Equals(typeof(T)));
  30. }
  31. }
  32. }