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

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

//**************************************************************************************************
/// <summary>
/// </summary>
public static partial class HGenericTypeChecking {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static void VerifyTypeOf<TComparand>(Type type)
{
   VerifyTypeOf( type, typeof(TComparand) );
}

public static void VerifyTypeOf(Type type,Type comparandType)
{
   HArgChecking.VerifyNotNulls( type, comparandType );
   if (!HType.IsTypeOf( type, comparandType ))
      throw HGenericTypeExceptionCreator.Create(
         "Generic type is not \"{0}\" type.",
         comparandType );
}

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

public static void VerifyByRef(Type type)
{
   HArgChecking.VerifyNotNull( type );
   if (!type.IsByRef)
      throw new HGenericTypeException(
         "Generic type is not reference type." );
}

public static void VerifyValueType(Type type)
{
   HArgChecking.VerifyNotNull( type );
   if (!type.IsValueType)
      throw new HGenericTypeException(
         "Generic type is not value type." );
}

public static void VerifyEnum(Type type)
{
   VerifyEnum( type, null );
}

public static void VerifyEnum(Type type,bool? flagsEnumerationRestriction)
{
   HArgChecking.VerifyNotNull( type );
   if ( !type.IsEnum )
      throw new HGenericTypeException(
         "Generic type is not enumeration." );
   if ( flagsEnumerationRestriction.HasValue &&
        flagsEnumerationRestriction.Value != HEnum.IsFlagsEnumeration( type ) )
      throw new HGenericTypeException(
         flagsEnumerationRestriction.Value ?
            "Generic type is not flags enumeration." :
            "Generic type is not nonflags enumeration." );
}

public static void VerifyFlagsEnum(Type type)
{
   VerifyEnum( type, true );
}

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

public static void VerifyStdValueType(Type type)
{
   HArgChecking.VerifyNotNull( type );
   if (!HType.IsStdValue( type ))
      throw new HGenericTypeException(
         "Generic type is not standard value type." );
}

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

public static void VerifyIntegralNumber(Type type)
{
   HArgChecking.VerifyNotNull( type );
   if (!HType.IsIntegralNumber( type ))
      throw new HGenericTypeException(
         "Generic type is not integral number type." );
}

public static void VerifyIntegralSignedlNumber(Type type)
{
   HArgChecking.VerifyNotNull( type );
   if (!HType.IsIntegralSignedNumber( type ))
      throw new HGenericTypeException(
         "Generic type is not integral signed number type." );
}

public static void VerifyIntegralUnsignedNumber(Type type)
{
   HArgChecking.VerifyNotNull( type );
   if (!HType.IsIntegralUnsignedNumber( type ))
      throw new HGenericTypeException(
         "Generic type is not integral unsigned number type." );
}

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

static HGenericTypeChecking()
{
   CommonHelpers_Core.Access();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HGenericTypeChecking
//**************************************************************************************************

} // CommonHelpers (.WASM)
