Skip to content

Commit

Permalink
make CultureContext treadsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
6bee committed Dec 20, 2024
1 parent 993385e commit f55a8e1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/Aqua.Tests/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Aqua.Tests;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;

public static class TestHelper
{
Expand Down Expand Up @@ -65,17 +66,20 @@ public static bool IsCollection(this Type type)

private sealed class CultureContext : IDisposable
{
private static readonly SemaphoreSlim _semaphore = new(1, 1);
private readonly CultureInfo _culture;

public CultureContext(CultureInfo culture)
{
_semaphore.Wait();
_culture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = culture;
}

public void Dispose()
{
CultureInfo.CurrentCulture = _culture;
_semaphore.Release();
}
}

Expand Down

0 comments on commit f55a8e1

Please sign in to comment.