CultureInfoUtilities Class

Provides utility methods for working with CultureInfo.

public static class CultureInfoUtilities

Methods

NameDescription
GetCulture(string?)Gets a culture by name or LCID, returning null if not found.
GetNeutralCulture(CultureInfo)Gets the neutral culture for a specific culture (e.g., "en" for "en-US").
NeutralEquals(CultureInfo, CultureInfo)Determines whether two cultures have the same neutral culture.
SetCurrentThreadCulture(CultureInfo)Sets the current thread's culture and UI culture.
UseCulture(CultureInfo, Action)Executes an action with a temporary culture, then restores the original culture.
UseCulture(string, Action)Executes an action with a temporary culture specified by name, then restores the original culture.
UseCulture<T>(CultureInfo, Func<T>)Executes a function with a temporary culture, then restores the original culture and returns the result.
UseCulture<T>(string, Func<T>)Executes a function with a temporary culture specified by name, then restores the original culture and returns the result.

GetCulture(string?)

CultureInfoUtilities.cs

Gets a culture by name or LCID, returning null if not found.

public static CultureInfo? GetCulture(string? name)

Parameters

name string?

Returns

CultureInfo?

GetNeutralCulture(CultureInfo)

CultureInfoUtilities.cs

Gets the neutral culture for a specific culture (e.g., "en" for "en-US").

public static CultureInfo GetNeutralCulture(this CultureInfo cultureInfo)

Parameters

cultureInfo CultureInfo

Returns

CultureInfo

NeutralEquals(CultureInfo, CultureInfo)

CultureInfoUtilities.cs

Determines whether two cultures have the same neutral culture.

public static bool NeutralEquals(this CultureInfo a, CultureInfo b)

Parameters

a CultureInfo
b CultureInfo

Returns

bool

SetCurrentThreadCulture(CultureInfo)

CultureInfoUtilities.cs

Sets the current thread's culture and UI culture.

public static void SetCurrentThreadCulture(CultureInfo cultureInfo)

Parameters

cultureInfo CultureInfo

UseCulture overloads

UseCulture(CultureInfo, Action)

CultureInfoUtilities.cs

Executes an action with a temporary culture, then restores the original culture.

public static void UseCulture(CultureInfo cultureInfo, Action action)
Parameters
cultureInfo CultureInfo
action Action

UseCulture(string, Action)

CultureInfoUtilities.cs

Executes an action with a temporary culture specified by name, then restores the original culture.

public static void UseCulture(string cultureName, Action action)
Parameters
cultureName string
action Action

UseCulture<T>(CultureInfo, Func<T>)

CultureInfoUtilities.cs

Executes a function with a temporary culture, then restores the original culture and returns the result.

public static T UseCulture<T>(CultureInfo cultureInfo, Func<T> action)
Type parameters
T
Parameters
cultureInfo CultureInfo
action Func<T>
Returns

T

UseCulture<T>(string, Func<T>)

CultureInfoUtilities.cs

Executes a function with a temporary culture specified by name, then restores the original culture and returns the result.

public static T UseCulture<T>(string cultureName, Func<T> action)
Type parameters
T
Parameters
cultureName string
action Func<T>
Returns

T