using System;
using System.Globalization;

namespace CommonHelpers {

//**************************************************************************************************
public static partial class HCultureInfo {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static CultureInfo CurrentUINeutralCulture
{
   get { return ToNeutral( CultureInfo.CurrentUICulture ); }
}

//==================================================================================================

public static NotSupportedException CreateNotSupportedOperationException()
{
   return CreateNotSupportedOperationException( CultureInfo.CurrentCulture );
}

public static NotSupportedException CreateNotSupportedOperationException
(
   [HOptional] CultureInfo culture
)
{
   return new NotSupportedException(string.Format(
      "Operation is not supported for this culture: \"{0}\".",
      culture ?? CultureInfo.InvariantCulture
   ));
}

//--------------------------------------------------------------------------------------------------

public static CultureInfo ToNeutral([HOptional] CultureInfo culture)
{
   for (var ci=culture;;ci=ci.Parent)
      if (ci==null || ci==CultureInfo.InvariantCulture)
         return CultureInfo.InvariantCulture;
      else
         if (ci.IsNeutralCulture)
            return ci==culture ? (CultureInfo)ci.Clone() : ci;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HCultureInfo
//**************************************************************************************************

} // CommonHelpers
