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.

33 lines
1.1 KiB

  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Web;
  7. namespace CounsellorBL.Helper
  8. {
  9. public static class AssemblyHelper
  10. {
  11. public static ConcurrentDictionary<string, Assembly> Load(Assembly a, string i_sPattern)
  12. {
  13. ConcurrentDictionary<string, Assembly> dicRes = new ConcurrentDictionary<string, Assembly>();
  14. if (a != null && i_sPattern != null)
  15. {
  16. FileInfo fi = new FileInfo(HttpUtility.UrlDecode(new Uri(a.CodeBase).AbsolutePath));
  17. FileInfo[] afi = fi.Directory.GetFiles(i_sPattern);
  18. foreach (FileInfo fiCur in afi)
  19. {
  20. if (!a.GetReferencedAssemblies().Any(x => x.Name == fiCur.Name))
  21. {
  22. #pragma warning disable S3885 // "Assembly.Load" should be used
  23. dicRes.TryAdd(fiCur.Name, Assembly.LoadFile(fiCur.FullName));
  24. #pragma warning restore S3885 // "Assembly.Load" should be used
  25. }
  26. }
  27. }
  28. return dicRes;
  29. }
  30. }
  31. }