//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// UserRTX.NET satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Reflection;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

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

static partial class trace {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[MethodImpl(MethodImplOptions.NoInlining)]
public static Task Do_A( string blockName, Func<Task> blockA ) =>
   _Do_A( Assembly.GetCallingAssembly(), blockName, blockA );
static async Task _Do_A( Assembly callingAssembly, string blockName, Func<Task> blockA )
{
   using ( new TRACE_IF( u.assembly.IsConfiguredForTrace( callingAssembly ),
                         blockName ) )
      await blockA();
}

/// <exception cref="ArgumentNullException" />
[MethodImpl(MethodImplOptions.NoInlining)]
public static Task Do_A( [u.req] MethodBase? method, Func<Task> blockA ) =>
   _Do_A( Assembly.GetCallingAssembly(), method, false, blockA );
/// <exception cref="ArgumentNullException" />
[MethodImpl(MethodImplOptions.NoInlining)]
public static Task Do_A( [u.req] MethodBase? method, bool expanded, Func<Task> blockA ) =>
   _Do_A( Assembly.GetCallingAssembly(), method, expanded, blockA );
static async Task _Do_A( Assembly callingAssembly,
                         [u.req] MethodBase? method, bool expanded, Func<Task> blockA )
{
   using ( new TRACE_IF( u.assembly.IsConfiguredForTrace( callingAssembly ),
                         method, expanded ) )
      await blockA();
}

/// <exception cref="ArgumentException" />
[MethodImpl(MethodImplOptions.NoInlining)]
public static Task Do_A( Type objectType, Func<Task> blockA,
                         [CallerMemberName] string memberName = "" ) =>
   _Do_A( Assembly.GetCallingAssembly(), objectType, blockA, memberName );
static async Task _Do_A( Assembly callingAssembly,
                         Type objectType, Func<Task> blockA,
                         [CallerMemberName] string memberName = "" )
{
   using ( new TRACE_IF( u.assembly.IsConfiguredForTrace( callingAssembly ),
                         objectType, memberName ) )
      await blockA();
}

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

[MethodImpl(MethodImplOptions.NoInlining)]
public static Task Do_A( bool condition, string blockName, Func<Task> blockA ) =>
   _Do_A( Assembly.GetCallingAssembly(), condition, blockName, blockA );
static async Task _Do_A( Assembly callingAssembly,
                         bool condition, string blockName, Func<Task> blockA )
{
   using ( new TRACE_IF( condition && u.assembly.IsConfiguredForTrace( callingAssembly ),
                         blockName ) )
      await blockA();
}

/// <exception cref="ArgumentNullException" />
[MethodImpl(MethodImplOptions.NoInlining)]
public static Task Do_A( bool condition, [u.req] MethodBase? method, Func<Task> blockA ) =>
   _Do_A( Assembly.GetCallingAssembly(), condition, method, false, blockA );
/// <exception cref="ArgumentNullException" />
[MethodImpl(MethodImplOptions.NoInlining)]
public static Task Do_A( bool condition, [u.req] MethodBase? method, bool expanded,
                         Func<Task> blockA ) =>
   _Do_A( Assembly.GetCallingAssembly(), condition, method, expanded, blockA );
static async Task _Do_A( Assembly callingAssembly,
                         bool condition, [u.req] MethodBase? method, bool expanded,
                         Func<Task> blockA )
{
   using ( new TRACE_IF( condition && u.assembly.IsConfiguredForTrace( callingAssembly ),
                         method, expanded ) )
      await blockA();
}

/// <exception cref="ArgumentException" />
[MethodImpl(MethodImplOptions.NoInlining)]
public static Task Do_A( bool condition, Type objectType, Func<Task> blockA,
                         [CallerMemberName] string memberName = "" ) =>
   _Do_A( Assembly.GetCallingAssembly(), condition, objectType, blockA, memberName );
static async Task _Do_A( Assembly callingAssembly,
                         bool condition, Type objectType, Func<Task> blockA,
                         [CallerMemberName] string memberName = "" )
{
   using ( new TRACE_IF( condition && u.assembly.IsConfiguredForTrace( callingAssembly ),
                         objectType, memberName ) )
      await blockA();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // trace

} // user_rtx (.wasm)
