namespace Spectre.Console;
///
/// Contains extension methods for .
///
public static class HasCultureExtensions
{
///
/// Sets the culture.
///
/// An object type with a culture.
/// The object to set the culture for.
/// The culture to set.
/// The same instance so that multiple calls can be chained.
public static T Culture(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;
}
///
/// Sets the culture.
///
/// An object type with a culture.
/// The object to set the culture for.
/// The culture to set.
/// The same instance so that multiple calls can be chained.
public static T Culture(this T obj, string name)
where T : class, IHasCulture
{
if (name is null)
{
throw new ArgumentNullException(nameof(name));
}
return Culture(obj, CultureInfo.GetCultureInfo(name));
}
///
/// Sets the culture.
///
/// An object type with a culture.
/// The object to set the culture for.
/// The culture to set.
/// The same instance so that multiple calls can be chained.
public static T Culture(this T obj, int culture)
where T : class, IHasCulture
{
return Culture(obj, CultureInfo.GetCultureInfo(culture));
}
}