Skip to content

Commit

Permalink
SDK: Add RETypeDefinition::has_attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Apr 1, 2024
1 parent 32bb18b commit 65cb249
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions shared/sdk/RETypeDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <execution>
#include <sstream>


#include <reframework/API.hpp>

#include "RETypeDB.hpp"
#include "RETypeDefinition.hpp"

Expand Down Expand Up @@ -785,6 +788,39 @@ bool RETypeDefinition::is_generic_type() const {
return get_generic_data() != nullptr;
}

bool RETypeDefinition::has_attribute(::REManagedObject* attribute_runtime_type, bool inherit) const {
if (attribute_runtime_type == nullptr) {
return false;
}

const auto runtime_type = this->get_runtime_type();

if (runtime_type == nullptr) {
return false;
}

const auto runtime_type_t = utility::re_managed_object::get_type_definition(runtime_type);

if (runtime_type_t == nullptr) {
return false;
}

const auto get_custom_attributes = runtime_type_t->get_method("GetCustomAttributes(System.Type, System.Boolean)");

if (get_custom_attributes == nullptr) {
return false;
}

const auto res = get_custom_attributes->invoke(runtime_type, std::vector<void*>{attribute_runtime_type, (void*)(uint64_t)inherit});
const auto attributes_array = (sdk::SystemArray*)res.ptr;

if (attributes_array == nullptr) {
return false;
}

return attributes_array->get_size() > 0;
}

uint32_t RETypeDefinition::get_crc_hash() const {
#if TDB_VER > 49
const auto t = get_type();
Expand Down
1 change: 1 addition & 0 deletions shared/sdk/RETypeDefinition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ struct RETypeDefinition : public sdk::RETypeDefinition_ {
bool is_primitive() const;
bool is_generic_type_definition() const;
bool is_generic_type() const;
bool has_attribute(::REManagedObject* attribute_runtime_type, bool inherit = false) const;

bool should_pass_by_pointer() const;

Expand Down

0 comments on commit 65cb249

Please sign in to comment.