#pragma once

#include "adapters/il2cpp/ManagedRuntime.h"

namespace ta::adapters::il2cpp
{
    template <typename T>
    [[nodiscard]] bool try_get_static_field(const Il2CppClass* clazz, const char* name, T& value)
    {
        if (!clazz || !name)
            return false;
        const FieldInfo* field = ManagedRuntime::field_or_null(clazz, name);
        if (!field)
            return false;
        il2cpp_field_static_get_value(const_cast<FieldInfo*>(field), static_cast<void*>(&value));
        return true;
    }

    template <typename T>
    [[nodiscard]] T get_method(const Il2CppClass* clazz, const char* name, const int args)
    {
        return ManagedRuntime::function<T>(clazz, name ? name : "", args);
    }
}
