InvariantCultureFixture.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using System.Globalization;
  5. using System.Threading;
  6. namespace Avalonia.UnitTests
  7. {
  8. /// <summary>
  9. /// Runs tests in the invariant culture.
  10. /// </summary>
  11. /// <remarks>
  12. /// Some tests check exception messages, and those from the .NET framework will be translated.
  13. /// Use this fixture to set the current culture to the invariant culture.
  14. /// </remarks>
  15. public class InvariantCultureFixture : IDisposable
  16. {
  17. private CultureInfo _restore;
  18. public InvariantCultureFixture()
  19. {
  20. #if NET461
  21. _restore = Thread.CurrentThread.CurrentCulture;
  22. Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  23. #else
  24. _restore = CultureInfo.CurrentCulture;
  25. CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
  26. #endif
  27. }
  28. public void Dispose()
  29. {
  30. #if NET461
  31. Thread.CurrentThread.CurrentCulture = _restore;
  32. #else
  33. CultureInfo.CurrentCulture = _restore;
  34. #endif
  35. }
  36. }
  37. }