终端一体化运控平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637
  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. }