mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2026-02-10 04:13:32 +01:00
* Revertf6e1368: "Fixes problems with extension blocks and params keyword" * Revert7965168: "Add modernization commit to .git-blame-ignore-revs" * Revert3f57df5: "Modernization of the code base"
62 lines
2.0 KiB
C#
62 lines
2.0 KiB
C#
namespace Spectre.Console;
|
|
|
|
/// <summary>
|
|
/// Contains extension methods for <see cref="IHasCulture"/>.
|
|
/// </summary>
|
|
public static class HasCultureExtensions
|
|
{
|
|
/// <summary>
|
|
/// Sets the culture.
|
|
/// </summary>
|
|
/// <typeparam name="T">An object type with a culture.</typeparam>
|
|
/// <param name="obj">The object to set the culture for.</param>
|
|
/// <param name="culture">The culture to set.</param>
|
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
|
public static T Culture<T>(this T obj, CultureInfo culture)
|
|
where T : class, IHasCulture
|
|
{
|
|
if (obj is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(obj));
|
|
}
|
|
|
|
if (culture is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(culture));
|
|
}
|
|
|
|
obj.Culture = culture;
|
|
return obj;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the culture.
|
|
/// </summary>
|
|
/// <typeparam name="T">An object type with a culture.</typeparam>
|
|
/// <param name="obj">The object to set the culture for.</param>
|
|
/// <param name="name">The culture to set.</param>
|
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
|
public static T Culture<T>(this T obj, string name)
|
|
where T : class, IHasCulture
|
|
{
|
|
if (name is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(name));
|
|
}
|
|
|
|
return Culture(obj, CultureInfo.GetCultureInfo(name));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the culture.
|
|
/// </summary>
|
|
/// <typeparam name="T">An object type with a culture.</typeparam>
|
|
/// <param name="obj">The object to set the culture for.</param>
|
|
/// <param name="culture">The culture to set.</param>
|
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
|
public static T Culture<T>(this T obj, int culture)
|
|
where T : class, IHasCulture
|
|
{
|
|
return Culture(obj, CultureInfo.GetCultureInfo(culture));
|
|
}
|
|
} |