Mirror of Svelto.ECS because we're a fan of it
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.

39 lines
1.0KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. public static class AssemblyUtility
  5. {
  6. static readonly List<Assembly> AssemblyList = new List<Assembly>();
  7. static AssemblyUtility()
  8. {
  9. var assemblyName = Assembly.GetExecutingAssembly().GetName();
  10. Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
  11. foreach (Assembly assembly in assemblies)
  12. {
  13. AssemblyName[] referencedAssemblies = assembly.GetReferencedAssemblies();
  14. if (Array.Exists(referencedAssemblies, (a) => a.Name == assemblyName.Name))
  15. {
  16. AssemblyList.Add(assembly);
  17. }
  18. }
  19. }
  20. public static IEnumerable<Type> GetTypesSafe(Assembly assembly)
  21. {
  22. try
  23. {
  24. Type[] types = assembly.GetTypes();
  25. return types;
  26. }
  27. catch (ReflectionTypeLoadException e)
  28. {
  29. return e.Types;
  30. }
  31. }
  32. public static List<Assembly> GetCompatibleAssemblies() { return AssemblyList; }
  33. }