Skip to content

Commit

Permalink
.NET: Add TypeDefinition::HasAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Apr 5, 2024
1 parent 852408b commit 4a1c9e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions csharp-api/REFrameworkNET/TypeDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,24 @@ namespace REFrameworkNET {
T TypeDefinition::As() {
return NativeProxy<T>::Create(gcnew NativeObject(this));
}

bool TypeDefinition::HasAttribute(REFrameworkNET::ManagedObject^ runtimeAttribute, bool inherit) {
if (runtimeAttribute == nullptr) {
return false;
}

auto runtimeType = this->GetRuntimeType();

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

auto attributes = (ManagedObject^)runtimeType->Call("GetCustomAttributes(System.Type, System.Boolean)", runtimeAttribute, inherit);

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

return (int)attributes->Call("GetLength", gcnew System::Int32(0)) > 0;
}
}
2 changes: 2 additions & 0 deletions csharp-api/REFrameworkNET/TypeDefinition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ public
}
}

bool HasAttribute(REFrameworkNET::ManagedObject^ runtimeAttribute, bool inherit);

/*Void* GetInstance()
{
return m_type->get_instance();
Expand Down

0 comments on commit 4a1c9e9

Please sign in to comment.