PoolManager.Prototypes.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #nullable enable
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using Robust.Shared.Utility;
  5. namespace Content.IntegrationTests;
  6. // Partial class for handling the discovering and storing test prototypes.
  7. public static partial class PoolManager
  8. {
  9. private static List<string> _testPrototypes = new();
  10. private const BindingFlags Flags = BindingFlags.Static
  11. | BindingFlags.NonPublic
  12. | BindingFlags.Public
  13. | BindingFlags.DeclaredOnly;
  14. private static void DiscoverTestPrototypes(Assembly assembly)
  15. {
  16. foreach (var type in assembly.GetTypes())
  17. {
  18. foreach (var field in type.GetFields(Flags))
  19. {
  20. if (!field.HasCustomAttribute<TestPrototypesAttribute>())
  21. continue;
  22. var val = field.GetValue(null);
  23. if (val is not string str)
  24. throw new Exception($"TestPrototypeAttribute is only valid on non-null string fields");
  25. _testPrototypes.Add(str);
  26. }
  27. }
  28. }
  29. }