TestsAllViews.cs 773 B

12345678910111213141516171819202122232425262728
  1. #nullable enable
  2. using Terminal.Gui;
  3. namespace UnitTests;
  4. /// <summary>
  5. /// Base class for tests that need to test all views.
  6. /// </summary>
  7. public class TestsAllViews
  8. {
  9. public static IEnumerable<object []> AllViewTypes =>
  10. typeof (View).Assembly
  11. .GetTypes ()
  12. .Where (type => type.IsClass && !type.IsAbstract && type.IsPublic && (type.IsSubclassOf (typeof (View)) || type == typeof (View)))
  13. .Select (type => new object [] { type });
  14. public static View CreateInstanceIfNotGeneric (Type type)
  15. {
  16. if (type.IsGenericType)
  17. {
  18. // Return null for generic types
  19. return null;
  20. }
  21. return Activator.CreateInstance (type) as View;
  22. }
  23. }