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

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

//**************************************************************************************************
public static partial class HArgChecking {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

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

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

public static void VerifyValueOf<TComparand>(object value)
{
   VerifyValueOf( value, typeof(TComparand) );
}
public static T VerifyValueOf<T,TComparand>(T value)
{
   VerifyValueOf<TComparand>( (object)value ); return value;
}

public static void VerifyValueOf(object value,Type comparandType)
{
   VerifyNotNull( value );
   if (!HType.IsValueOf( value, comparandType ))
      throw HArgTypeExceptionCreator.Create(
         "Value is not of \"{0}\" type.", comparandType );
}
public static T VerifyValueOf<T>(T value,Type comparandType)
{
   VerifyValueOf( (object)value, comparandType ); return value;
}

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

public static Type VerifyTypeIsByRef(Type type)
{
   VerifyNotNull( type );
   if (!type.IsByRef)
      throw HArgTypeExceptionCreator.Create(
         "Type \"{0}\" is not reference type.", type );
   return type;
}

public static Type VerifyTypeIsValueType(Type type)
{
   VerifyNotNull( type );
   if (!type.IsValueType)
      throw HArgTypeExceptionCreator.Create(
         "Type \"{0}\" is not value type.", type );
   return type;
}

public static Type VerifyTypeIsEnum(Type type)
{
   VerifyNotNull( type );
   if (!type.IsEnum)
      throw HArgTypeExceptionCreator.Create(
         "Type \"{0}\" is not enumeration.", type );
   return type;
}

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

public static Type VerifyTypeIsStdValue(Type type)
{
   VerifyNotNull( type );
   if (!HType.IsStdValue( type ))
      throw HArgTypeExceptionCreator.Create(
         "Type \"{0}\" is not standard value type.", type );
   return type;
}

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

public static Type VerifyTypeIsIntegral(Type type)
{
   VerifyNotNull( type );
   if (!HType.IsIntegralNumber( type ))
      throw HArgTypeExceptionCreator.Create(
         "Type \"{0}\" is not integral type.", type );
   return type;
}

public static Type VerifyTypeIsIntegralSignedlNumber(Type type)
{
   VerifyNotNull( type );
   if (!HType.IsIntegralSignedNumber( type ))
      throw HArgTypeExceptionCreator.Create(
         "Type \"{0}\" is not integral signed number type.", type );
   return type;
}

public static Type VerifyTypeIsIntegralUnsignedNumber(Type type)
{
   VerifyNotNull( type );
   if (!HType.IsIntegralUnsignedNumber( type ))
      throw HArgTypeExceptionCreator.Create(
         "Type \"{0}\" is not integral unsigned number type.", type );
   return type;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HArgChecking
//**************************************************************************************************

} // CommonHelpers (.WASM)
