Analyzer.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using dnlib.DotNet;
  8. using HybridCLR.Editor.Meta;
  9. using UnityEditor;
  10. using IAssemblyResolver = HybridCLR.Editor.Meta.IAssemblyResolver;
  11. namespace HybridCLR.Editor.Link
  12. {
  13. public class Analyzer
  14. {
  15. private readonly IAssemblyResolver _resolver;
  16. public Analyzer(IAssemblyResolver resolver)
  17. {
  18. _resolver = resolver;
  19. }
  20. public HashSet<TypeRef> CollectRefs(List<string> rootAssemblies)
  21. {
  22. using (var assCollector = new AssemblyCache(_resolver))
  23. {
  24. var rootAssemblyNames = new HashSet<string>(rootAssemblies);
  25. var typeRefs = new HashSet<TypeRef>(TypeEqualityComparer.Instance);
  26. foreach (var rootAss in rootAssemblies)
  27. {
  28. var dnAss = assCollector.LoadModule(rootAss, false);
  29. foreach (var type in dnAss.GetTypeRefs())
  30. {
  31. if (!rootAssemblyNames.Contains(type.DefinitionAssembly.Name.ToString()))
  32. {
  33. typeRefs.Add(type);
  34. }
  35. }
  36. }
  37. assCollector.Dispose();
  38. return typeRefs;
  39. }
  40. }
  41. }
  42. }