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

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

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

public static object GetStaticValue(Type type,string fieldName)
{
   return GetStaticValueUsingVisibilityFlags(type,fieldName,BindingFlags.Public);
}

public static void SetStaticValue(Type type,string fieldName,object value)
{
   SetStaticValueUsingVisibilityFlags(type,fieldName,BindingFlags.Public,value);
}

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

public static object GetInstanceValue(object obj,string fieldName)
{
   return GetInstanceValueUsingVisibilityFlags(obj,fieldName,BindingFlags.Public);
}

public static void SetInstanceValue(object obj,string fieldName,object value)
{
   SetInstanceValueUsingVisibilityFlags(obj,fieldName,BindingFlags.Public,value);
}

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

public static object GetStaticValueUsingVisibilityFlags( Type type,
                                                         string fieldName,
                                                         BindingFlags visibilityFlags )
{
   return type.InvokeMember( fieldName,
      visibilityFlags | BindingFlags.Static | BindingFlags.GetField,
      null, null, new object[0] );
}

public static void SetStaticValueUsingVisibilityFlags( Type type,
                                                       string fieldName,
                                                       BindingFlags visibilityFlags,
                                                       object value )
{
   type.InvokeMember( fieldName,
      visibilityFlags | BindingFlags.Static | BindingFlags.SetField,
      null, null, new object[]{value} );
}

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

public static object GetInstanceValueUsingVisibilityFlags( object obj,
                                                           string fieldName,
                                                           BindingFlags visibilityFlags )
{
   return obj.GetType().InvokeMember( fieldName,
      visibilityFlags | BindingFlags.Instance | BindingFlags.GetField,
      null, null, new object[0] );
}

public static void SetInstanceValueUsingVisibilityFlags( object obj,
                                                         string fieldName,
                                                         BindingFlags visibilityFlags,
                                                         object value )
{
   obj.GetType().InvokeMember( fieldName,
      visibilityFlags | BindingFlags.Instance | BindingFlags.SetField,
      null, null, new object[]{value} );
}

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

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

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HFieldInfo
//**************************************************************************************************

} // CommonHelpers (.WASM)
