//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// CommonHelpers satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Reflection;
using System.Globalization;

#if !WASM
namespace CommonHelpers {
#else
namespace CommonHelpers.WASM {
#endif

//**************************************************************************************************
partial class HValueParser {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static T Parse<T>(string src) where T: struct
   { return Parse<T>(src,(object[])null); }
public static T Parse<T>(string src,T def) where T: struct
   { return Parse<T>(src,(object[])null,def); }

public static T Parse<T>(string src,IFormatProvider provider) where T: struct
   { return Parse<T>(src,new object[]{provider}); }
public static T Parse<T>(string src,IFormatProvider provider,T def) where T: struct
   { return Parse<T>(src,new object[]{provider},def); }

public static T Parse<T>(string src,[HOptional] object[] additionalParams) where T: struct
   { return ParseEx<T>(src,additionalParams,null); }
public static T Parse<T>(string src,[HOptional] object[] additionalParams,T def) where T: struct
   { return ParseEx<T>(src,additionalParams,def); }

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

public static T ParseInvariant<T>(string src) where T: struct
   { return Parse<T>(src,new object[]{(IFormatProvider)null}); }
public static T ParseInvariant<T>(string src,T def) where T: struct
   { return Parse<T>(src,new object[]{(IFormatProvider)null},def); }

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

public static T ParseWithProviderEx<T>(string src,IFormatProvider provider,T? def) where T: struct
{
   return ParseEx<T>( src, new object[]{ provider }, def );
}
public static T ParseWithParamsEx<T>( string src,
                                      [HOptional] object[] additionalParams,
                                      T? def ) where T: struct
{
   return ParseEx<T>( src, additionalParams, def );
}
public static T ParseInvariantEx<T>(string src,T? def) where T: struct
{
   return ParseEx<T>( src, new object[]{ (IFormatProvider)null }, def );
}

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

internal static T ParseEx<T>(string src,[HOptional] object[] additionalParams,T? def)
   where T: struct
{
   T result; HParseValueException e;
   if (!TryParseEx(src,additionalParams,def,out result,out e))
      throw e;
   return result;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HValueParser
//**************************************************************************************************

} // CommonHelpers (.WASM)
