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

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

/// <summary>
/// Dispolable errors (exception creation)
/// </summary>
public static class disposable_errors {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static ObjectDisposedException OBJECT_DISPOSED( Type objectType ) =>
   new ObjectDisposedException( objectType.ToString() );

public static InvalidOperationException NOT_DISPOSED_SYNCHRONOUSLY(
   Type objectType, StackTrace? creationStack )
{
   var sb = new StringBuilder(u.str.FMT(
      "Object of type “{0}” was not disposed synchronously.",
      objectType ));
   if ( creationStack != null ) {
      u.text.AppendLine( sb,
         "___ Object creation stack: ___" );
      u.text.AppendLine( sb, stack_trace.ToText( creationStack ) );
   }
   return new InvalidOperationException( sb.ToString() );
}

public static NotSupportedException MUST_DISPOSE_SYNCHRONOUSLY_IN_ASYNC_MODE( Type objectType ) =>
   new NotSupportedException(u.str.FMT(
      "Object of type “{0}” must be disposed synchronously in async.mode.",
      objectType ));

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // disposable_errors

} // user_rtx (.wasm)
