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

#if !WASM
namespace user_rtx { using u = user_rtx;
#else
namespace user_rtx.wasm { using u = user_rtx.wasm;
#endif

static partial class enum_val {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[u.failure_as_null]
public static Exception? CatchParse<EnumType>( out EnumType value, string src, EnumType? def=null )
where EnumType: struct =>
   CatchParseX<EnumType>( out value, src, def, 0 );

[u.failure_as_null]
public static Exception? CatchParse<EnumType>( out EnumType value,
                                               string src, char? separator,
                                               EnumType? def=null )
where EnumType: struct =>
   CatchParseX<EnumType>( out value, src, separator, def, 0 );

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

[u.failure_as_null]
public static Exception? CatchParseX<EnumType>( out EnumType value, string src, EnumType? def,
                                                u.enum_parse_options options )
where EnumType: struct
{
   try {
      value = ParseX( src, def, options );
   }
   catch ( Exception e ) {
      value = default;
      return e;
   }
   return null;
}

[u.failure_as_null]
public static Exception? CatchParseX<EnumType>( out EnumType value,
                                                string src, char? separator, EnumType? def,
                                                u.enum_parse_options options )
where EnumType: struct
{
   try {
      value = ParseX( src, separator, def, options );
   }
   catch ( Exception e ) {
      value = default;
      return e;
   }
   return null;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // enum_val

} // user_rtx (.wasm)
