TestServices.cs 967 B

123456789101112131415161718192021222324252627282930
  1. // -----------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. // -----------------------------------------------------------------------
  4. using System;
  5. using System.Reflection;
  6. using System.Collections.Generic;
  7. namespace System.UnitTesting
  8. {
  9. public static class TestServices
  10. {
  11. public static string GenerateRandomString()
  12. {
  13. return Guid.NewGuid().ToString().Replace('-', '_');
  14. }
  15. public static IEnumerable<TEnum> GetEnumValues<TEnum>() where TEnum : struct
  16. { // Silverlight 2.0 does not have Enum.GetValues()
  17. // so we need to write our own
  18. foreach (FieldInfo field in typeof(TEnum).GetFields())
  19. {
  20. if (!field.IsLiteral)
  21. continue;
  22. yield return (TEnum)field.GetRawConstantValue();
  23. }
  24. }
  25. }
  26. }