// Copyright (C) Stichting Deltares 2025. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Globalization;
using System.Threading;
namespace Deltares.Maps;
public static class CultureHelper
{
public static void InvokeWithDutchCulture(Action action)
{
var nlCulture = new CultureInfo("nl-NL");
InvokeWithCulture(nlCulture, action);
}
public static void InvokeWithUSCulture(Action action)
{
var usCulture = new CultureInfo("en-US");
InvokeWithCulture(usCulture, action);
}
public static T InvokeWithDutchCulture(Func func)
{
var culture = new CultureInfo("nl-NL");
return InvokeWithCulture(culture, func);
}
public static T InvokeWithUSCulture(Func func)
{
var culture = new CultureInfo("en-US");
return InvokeWithCulture(culture, func);
}
public static T InvokeWithCulture(CultureInfo targetCulture, Func func)
{
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
try
{
// set the current thread to dutch culture to mimic floating piont numbers with a comma
Thread.CurrentThread.CurrentCulture = targetCulture;
return func();
}
finally
{
Thread.CurrentThread.CurrentCulture = currentCulture;
}
}
public static void InvokeWithCulture(CultureInfo targetCulture, Action testAction)
{
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
try
{
// set the current thread to dutch culture to mimic floating piont numbers with a comma
Thread.CurrentThread.CurrentCulture = targetCulture;
testAction();
}
finally
{
Thread.CurrentThread.CurrentCulture = currentCulture;
}
}
}