Index: src/Common/DelftTools.Utils/Globalization/RegionalSettingsManager.cs
===================================================================
diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a
--- src/Common/DelftTools.Utils/Globalization/RegionalSettingsManager.cs (.../RegionalSettingsManager.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9)
+++ src/Common/DelftTools.Utils/Globalization/RegionalSettingsManager.cs (.../RegionalSettingsManager.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a)
@@ -12,17 +12,17 @@
///
public static class RegionalSettingsManager
{
- private static readonly CustomFormatProvider customFormatProvider = new CustomFormatProvider();
-
public static event Action LanguageChanged;
public static event Action FormatChanged;
+ private static readonly CustomFormatProvider customFormatProvider = new CustomFormatProvider();
private static string realNumberFormat = "G5";
-
+
///
/// Language in the form of standard cultures "en-US", "ru-RU" ...
///
- public static string Language {
+ public static string Language
+ {
set
{
var ci = new CultureInfo(value)
@@ -34,7 +34,7 @@
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = ci;
- if(LanguageChanged != null)
+ if (LanguageChanged != null)
{
LanguageChanged();
}
@@ -46,31 +46,14 @@
}
}
- private static DateTimeFormatInfo CreateDateTimeFormatFromSystemSettingsWithoutNameLocalization()
- {
- var systemCulture = Thread.CurrentThread.CurrentCulture.DateTimeFormat;
- var ci = CultureInfo.InvariantCulture;
-
- var localMachineDateTimeFormat = (DateTimeFormatInfo)systemCulture.Clone();
- //don't take the localized names!
- localMachineDateTimeFormat.DayNames = ci.DateTimeFormat.DayNames;
- localMachineDateTimeFormat.MonthNames = ci.DateTimeFormat.MonthNames;
- localMachineDateTimeFormat.AbbreviatedDayNames = ci.DateTimeFormat.AbbreviatedDayNames;
- localMachineDateTimeFormat.AbbreviatedMonthGenitiveNames = ci.DateTimeFormat.AbbreviatedMonthGenitiveNames;
- localMachineDateTimeFormat.AbbreviatedMonthNames = ci.DateTimeFormat.AbbreviatedMonthNames;
- return localMachineDateTimeFormat;
- }
-
public static CultureInfo CurrentCulture
{
- get { return Thread.CurrentThread.CurrentCulture; }
+ get
+ {
+ return Thread.CurrentThread.CurrentCulture;
+ }
}
- public static IFormatProvider GetCustomFormatProvider()
- {
- return customFormatProvider;
- }
-
///
/// TODO: make it configurable
///
@@ -90,30 +73,58 @@
///
public static string RealNumberFormat
{
- get
+ get
{
return realNumberFormat;
}
set
{
realNumberFormat = value;
- if(FormatChanged != null)
+ if (FormatChanged != null)
{
FormatChanged();
}
}
}
+ public static IFormatProvider GetCustomFormatProvider()
+ {
+ return customFormatProvider;
+ }
+
+ public static string ConvertToString(object value, bool truncateNumbers = true)
+ {
+ if (value is DateTime)
+ {
+ return ((DateTime) value).ToString(DateTimeFormat);
+ }
+ if (truncateNumbers && (value is double || value is float || value is decimal))
+ {
+ return ((double) value).ToString(RealNumberFormat);
+ }
+ return Convert.ToString(value, CurrentCulture);
+ }
+
+ private static DateTimeFormatInfo CreateDateTimeFormatFromSystemSettingsWithoutNameLocalization()
+ {
+ var systemCulture = Thread.CurrentThread.CurrentCulture.DateTimeFormat;
+ var ci = CultureInfo.InvariantCulture;
+
+ var localMachineDateTimeFormat = (DateTimeFormatInfo) systemCulture.Clone();
+ //don't take the localized names!
+ localMachineDateTimeFormat.DayNames = ci.DateTimeFormat.DayNames;
+ localMachineDateTimeFormat.MonthNames = ci.DateTimeFormat.MonthNames;
+ localMachineDateTimeFormat.AbbreviatedDayNames = ci.DateTimeFormat.AbbreviatedDayNames;
+ localMachineDateTimeFormat.AbbreviatedMonthGenitiveNames = ci.DateTimeFormat.AbbreviatedMonthGenitiveNames;
+ localMachineDateTimeFormat.AbbreviatedMonthNames = ci.DateTimeFormat.AbbreviatedMonthNames;
+ return localMachineDateTimeFormat;
+ }
+
///
/// TODO: how to make .NET use this FormatProvider instead of CurrentCulture.NumberInfo? Sealed class problem
///
private class CustomFormatProvider : IFormatProvider, ICustomFormatter
{
- public object GetFormat(Type formatType)
- {
- return (formatType == typeof(ICustomFormatter)) ? this : null;
- }
-
public string Format(string format, object arg, IFormatProvider formatProvider)
{
var argType = arg.GetType();
@@ -124,19 +135,11 @@
return string.Format(CurrentCulture, format, arg);
}
- }
- public static string ConvertToString(object value, bool truncateNumbers=true)
- {
- if (value is DateTime)
+ public object GetFormat(Type formatType)
{
- return ((DateTime) value).ToString(DateTimeFormat);
+ return (formatType == typeof(ICustomFormatter)) ? this : null;
}
- if (truncateNumbers && (value is double || value is float || value is decimal))
- {
- return ((double) value).ToString(RealNumberFormat);
- }
- return Convert.ToString(value, CurrentCulture);
}
}
}
\ No newline at end of file