Created
September 18, 2016 10:06
-
-
Save nordinrahman/7a7174f254d8f3fcebda43047409d9c7 to your computer and use it in GitHub Desktop.
Custom CultureInfo class, to be used, when instantiation of CultureInfo trigger CultureNotFoundException. Only support locale-name with format xx-XX.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Globalization; | |
using System.Text.RegularExpressions; | |
namespace CustomeCultureInfo | |
{ | |
/// <summary> | |
/// Custom culture info | |
/// </summary> | |
public class CustomCultureInfo : CultureInfo | |
{ | |
public CustomCultureInfo(string name) : base(GetParentCulture(name)) | |
{ | |
Name = name; | |
Parent = new CultureInfo(GetParentCulture(name)); | |
} | |
private static string GetParentCulture(string name) | |
{ | |
return Regex.Match(name, @"^\w+-(\w+)").Groups[1].Value; | |
} | |
public override string Name { get; } | |
public override CultureInfo Parent { get; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment