From c0ed7f9b264d27875c8ce3307c025d88a3c53f3a Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 16 May 2019 16:24:31 -0400 Subject: [PATCH] feat: Clarifying neutral culture exception --- .../Globalization/IcdCultureInfo.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ICD.Common.Utils/Globalization/IcdCultureInfo.cs b/ICD.Common.Utils/Globalization/IcdCultureInfo.cs index 6d69426..0b31684 100644 --- a/ICD.Common.Utils/Globalization/IcdCultureInfo.cs +++ b/ICD.Common.Utils/Globalization/IcdCultureInfo.cs @@ -201,7 +201,9 @@ namespace ICD.Common.Utils.Globalization { if (m_IsResident) return base.DateTimeFormat; - CheckNeutral(this); + + ThrowIfNeutralCulture(this); + if (m_DatetimeFormat == null) { DateTimeFormatInfo dateTimeFormatInfo = GetDateTimeFormat(m_DatetimeFormatId); @@ -218,7 +220,7 @@ namespace ICD.Common.Utils.Globalization base.DateTimeFormat = value; return; } - VerifyWritable(); + ThrowIfReadOnly(); if (value == null) throw new ArgumentException("value"); m_DatetimeFormat = value; @@ -241,7 +243,9 @@ namespace ICD.Common.Utils.Globalization { if (m_IsResident) return base.NumberFormat; - CheckNeutral(this); + + ThrowIfNeutralCulture(this); + if (m_NumberFormat == null) { NumberFormatInfo numberFormatInfo = GetNumberFormat(m_NumberFormatId); @@ -258,7 +262,7 @@ namespace ICD.Common.Utils.Globalization base.NumberFormat = value; return; } - VerifyWritable(); + ThrowIfReadOnly(); if (value == null) throw new ArgumentException("value"); m_NumberFormat = value; @@ -985,16 +989,16 @@ namespace ICD.Common.Utils.Globalization #endregion - private void VerifyWritable() + private void ThrowIfReadOnly() { if (IsReadOnly) throw new InvalidOperationException(); } - private static void CheckNeutral(CultureInfo culture) + private static void ThrowIfNeutralCulture(CultureInfo culture) { if (culture.IsNeutralCulture) - throw new NotSupportedException(); + throw new NotSupportedException("A neutral culture does not provide enough information to display the correct numeric format"); } private static bool IsResident(string name)