暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

InterceptedEventsPreviewTests.cs 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Reflection;
  3. using System.Collections.Generic;
  4. using UnityEngine.EventSystems;
  5. using UnityEditor;
  6. using NUnit.Framework;
  7. public class InterceptedEventsPreviewTests
  8. {
  9. [Test]
  10. public void InterceptedEventsPreviewCacheUsingTypeCacheReturnsSameTypes()
  11. {
  12. var typeCacheEventInterfaces = new List<Type>();
  13. TypeCache.TypeCollection types = TypeCache.GetTypesDerivedFrom<IEventSystemHandler>();
  14. foreach (var type in types)
  15. {
  16. if (!type.IsInterface)
  17. continue;
  18. typeCacheEventInterfaces.Add(type);
  19. }
  20. var appDomainEventInterfaces = new List<Type>();
  21. foreach (var type in GetAccessibleTypesInLoadedAssemblies())
  22. {
  23. if (!type.IsInterface)
  24. continue;
  25. appDomainEventInterfaces.Add(type);
  26. }
  27. Assert.AreNotEqual(typeCacheEventInterfaces.Count, appDomainEventInterfaces.Count, "Did not find the same number of EventInterface types");
  28. for (int i = 0; i < typeCacheEventInterfaces.Count; ++i)
  29. {
  30. Assert.Contains(typeCacheEventInterfaces[i], appDomainEventInterfaces);
  31. }
  32. }
  33. private static IEnumerable<Type> GetAccessibleTypesInLoadedAssemblies()
  34. {
  35. var assemblies = AppDomain.CurrentDomain.GetAssemblies();
  36. for (var i = 0; i < assemblies.Length; ++i)
  37. {
  38. Type[] types;
  39. var assembly = assemblies[i];
  40. if (assembly == null)
  41. continue;
  42. try
  43. {
  44. types = assembly.GetTypes();
  45. }
  46. catch (ReflectionTypeLoadException e)
  47. {
  48. // assembly.GetTypes() might fail in case the Assembly cannot resolve all its references,
  49. // or in case it was built targetting a newer version of .NET.
  50. // In case the resolution fails for some types, we can still access the ones that have been
  51. // properly loaded.
  52. types = e.Types;
  53. }
  54. for (var j = 0; j < types.Length; ++j)
  55. {
  56. var type = types[j];
  57. if (type == null)
  58. continue;
  59. yield return type;
  60. }
  61. }
  62. }
  63. }