Table of Contents

Class CultureInfoExtensions

Namespace
Codebelt.Extensions.Globalization
Assembly
Codebelt.Extensions.Globalization.dll

Extension methods for the CultureInfo class.

public static class CultureInfoExtensions
Inheritance
CultureInfoExtensions

Examples

CultureInfoExtensions

The following example shows how to enrich a culture with Windows NLS formatting information for consumer-facing date and number patterns.

using System;
using System.Globalization;
using Codebelt.Extensions.Globalization;

namespace Demo;

public static class Sample
{
    public static void Run()
    {
        CultureInfo culture = CultureInfo.GetCultureInfo("da-DK");
        CultureInfo enriched = culture.UseNationalLanguageSupport();

        Console.WriteLine(enriched.DateTimeFormat.ShortDatePattern);
    }
}

Methods

UseNationalLanguageSupport(IEnumerable<CultureInfo>)

Enriches the specified cultures with the original Windows variant.

public static IEnumerable<CultureInfo> UseNationalLanguageSupport(this IEnumerable<CultureInfo> cultures)

Parameters

cultures IEnumerable<CultureInfo>

The sequence of CultureInfo to extend.

Returns

IEnumerable<CultureInfo>

A sequence of CultureInfo objects enriched with the original Windows variant.

Remarks

Replaces the value on the public writable properties of DateTimeFormat and NumberFormat to favor NLS (https://learn.microsoft.com/en-us/windows/win32/intl/national-language-support) instead of ICU (http://site.icu-project.org/home).

Exceptions

ArgumentNullException

cultures is null.

UseNationalLanguageSupport(CultureInfo)

Enriches the specified culture with the original Windows variant.

public static CultureInfo UseNationalLanguageSupport(this CultureInfo culture)

Parameters

culture CultureInfo

The of CultureInfo to extend.

Returns

CultureInfo

A CultureInfo object enriched with the original Windows variant.

Remarks

Replaces the value on the public writable properties of DateTimeFormat and NumberFormat to favor NLS (https://learn.microsoft.com/en-us/windows/win32/intl/national-language-support) instead of ICU (http://site.icu-project.org/home).

Exceptions

ArgumentNullException

culture is null.