How to use Handle in a managed ref class

Hi, I need to have a reference to an Handle in a managed ref class and set it from a derived class, with a derived Handle type. with an old OCC version I could do this as shown in the sample code below.
Now how it's possible to do this with the new implementation of Handle ?

public ref class MyBaseClass
{
protected:
Handle(Standard_Transient)* _handle;

public:
MyBaseClass() {}

MyBaseClass(const Handle(Standard_Transient)& handle)
{
_handle = new Handle_Standard_Transient(handle);
}
}

public ref class MyDerivedClass : public MyBaseClass
{
public:
MyDerivedClass(const Handle(Standard_Type)& handle) : MyBaseClass()
{
_handle = new Handle_Standard_Type(handle);
}
}

Andrey BETENEV's picture

Hello,

Consider using NCollection_Haft class. This should do the job:

#include <NCollection_Haft.h>

public ref class MyBaseClass
{
protected:
NCollection_Haft<Handle(Standard_Transient)> _handle;

public:
MyBaseClass() {}

MyBaseClass(const Handle(Standard_Transient)& handle)
{
_handle() = handle;
}
}

public ref class MyDerivedClass : public MyBaseClass
{
public:
MyDerivedClass(const Handle(Standard_Type)& handle) : MyBaseClass()
{
_handle() = handle;
}
}