Skip to content

Commit

Permalink
.NET: Add IObject::As<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Mar 26, 2024
1 parent 08ca8c6 commit 513663f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions csharp-api/REFrameworkNET/IObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ public interface class IObject {

virtual InvokeRet^ Invoke(System::String^ methodName, array<System::Object^>^ args);
bool HandleInvokeMember_Internal(System::String^ methodName, array<System::Object^>^ args, System::Object^% result);

// For interface types
generic <typename T>
T As();
};
}
6 changes: 6 additions & 0 deletions csharp-api/REFrameworkNET/ManagedObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Method.hpp"

#include "ManagedObject.hpp"
#include "Proxy.hpp"

#include "API.hpp"

Expand Down Expand Up @@ -261,4 +262,9 @@ namespace REFrameworkNET {

return false;
}

generic <typename T>
T ManagedObject::As() {
return ManagedProxy<T>::Create(this);
}
}
3 changes: 3 additions & 0 deletions csharp-api/REFrameworkNET/ManagedObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ public ref class ManagedObject : public System::Dynamic::DynamicObject, public S
virtual bool TryGetMember(System::Dynamic::GetMemberBinder^ binder, System::Object^% result) override;
virtual bool TrySetMember(System::Dynamic::SetMemberBinder^ binder, System::Object^ value) override;

generic <typename T>
virtual T As();

// TODO methods:
/*public Void* GetReflectionProperties() {
return _original.get_reflection_properties();
Expand Down
6 changes: 6 additions & 0 deletions csharp-api/REFrameworkNET/NativeObject.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "InvokeRet.hpp"
#include "Method.hpp"
#include "NativeObject.hpp"
#include "Proxy.hpp"

#include "API.hpp"

Expand Down Expand Up @@ -42,4 +43,9 @@ bool NativeObject::TryInvokeMember(System::Dynamic::InvokeMemberBinder^ binder,
{
return HandleInvokeMember_Internal(binder->Name, args, result);
}

generic <typename T>
T NativeObject::As() {
return NativeProxy<T>::Create(this);
}
}
3 changes: 3 additions & 0 deletions csharp-api/REFrameworkNET/NativeObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public ref class NativeObject : public System::Dynamic::DynamicObject, public Sy
virtual bool HandleInvokeMember_Internal(System::String^ methodName, array<System::Object^>^ args, System::Object^% result);
virtual bool TryInvokeMember(System::Dynamic::InvokeMemberBinder^ binder, array<System::Object^>^ args, System::Object^% result) override;

generic <typename T>
virtual T As();

public:
// IEnumerable implementation
virtual System::Collections::IEnumerator^ GetEnumerator() {
Expand Down

0 comments on commit 513663f

Please sign in to comment.