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

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

//**************************************************************************************************
partial class HEnum {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static bool TryParse<EnumType>(string src,out EnumType dst)
   where EnumType: struct
{
   return TryParse<EnumType>(src,null,HEnumParsingOptions.None,null,out dst);
}

public static bool TryParse<EnumType>(string src,HEnumParsingOptions options,out EnumType dst)
   where EnumType: struct
{
   return TryParse<EnumType>(src,null,options,null,out dst);
}

public static bool TryParse<EnumType>(string src,EnumType def,out EnumType dst)
   where EnumType: struct
{
   return TryParse<EnumType>(src,null,HEnumParsingOptions.None,def,out dst);
}

public static bool TryParse<EnumType>( string src, HEnumParsingOptions options,
                                       EnumType def, out EnumType dst )
   where EnumType: struct
{
   return TryParse<EnumType>(src,null,options,def,out dst);
}

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

public static bool TryParse<EnumType>(string src,char? separator,out EnumType dst)
   where EnumType: struct
{
   return TryParse<EnumType>(src,separator,HEnumParsingOptions.None,null,out dst);
}

public static bool TryParse<EnumType>( string src, char? separator,
                                       HEnumParsingOptions options,
                                       out EnumType dst )
   where EnumType: struct
{
   return TryParse<EnumType>(src,separator,options,null,out dst);
}

public static bool TryParse<EnumType>( string src, char? separator,
                                       EnumType def, out EnumType dst )
   where EnumType: struct
{
   return TryParse<EnumType>(src,separator,HEnumParsingOptions.None,def,out dst);
}

public static bool TryParse<EnumType>( string src,  char? separator,
                                       HEnumParsingOptions options, EnumType def,
                                       out EnumType dst )
   where EnumType: struct
{
   return TryParse<EnumType>(src,separator,options,def,out dst);
}

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

public static bool TryParse<EnumType>(string src,out EnumType dst,out string err)
   where EnumType: struct
{
   return TryParse<EnumType>(src,null,HEnumParsingOptions.None,null,out dst,out err);
}

public static bool TryParse<EnumType>( string src, HEnumParsingOptions options,
                                       out EnumType dst, out string err )
   where EnumType: struct
{
   return TryParse<EnumType>(src,null,options,null,out dst,out err);
}

public static bool TryParse<EnumType>( string src, EnumType def,
                                       out EnumType dst, out string err )
   where EnumType: struct
{
   return TryParse<EnumType>(src,null,HEnumParsingOptions.None,def,out dst,out err);
}

public static bool TryParse<EnumType>( string src, HEnumParsingOptions options, EnumType def,
                                       out EnumType dst, out string err )
   where EnumType: struct
{
   return TryParse<EnumType>(src,null,options,def,out dst,out err);
}

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

public static bool TryParse<EnumType>(string src,char? separator,out EnumType dst,out string err)
   where EnumType: struct
{
   return TryParse<EnumType>(src,separator,HEnumParsingOptions.None,null,out dst,out err);
}

public static bool TryParse<EnumType>( string src, char? separator, HEnumParsingOptions options,
                                       out EnumType dst, out string err )
   where EnumType: struct
{
   return TryParse<EnumType>(src,separator,options,null,out dst,out err);
}

public static bool TryParse<EnumType>( string src, char? separator, EnumType def,
                                       out EnumType dst, out string err )
   where EnumType: struct
{
   return TryParse<EnumType>(src,separator,HEnumParsingOptions.None,def,out dst,out err);
}

public static bool TryParse<EnumType>( string src, char? separator,
                                       HEnumParsingOptions options, EnumType def,
                                       out EnumType dst, out string err )
   where EnumType: struct
{
   return TryParse<EnumType>(src,separator,options,def,out dst,out err);
}

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

static bool TryParse<EnumType>( string src, char? separator,
                                HEnumParsingOptions options,
                                EnumType? def, out EnumType dst )
   where EnumType: struct
{
   string err; return TryParse(src,separator,options,def,out dst,out err);
}

static bool TryParse<EnumType>( string src, char? separator,
                                HEnumParsingOptions options, EnumType? def,
                                out EnumType dst, out string err )
   where EnumType: struct
{
   try
   {
      dst=Parse(src,null,options,def);
   }
   catch (HParseValueException e)
   {
      dst=default(EnumType); err=e.Message; return false;
   }
   err=null; return true;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HEnum
//**************************************************************************************************

} // CommonHelpers (.WASM)
