How can I write my own template backup storage for a universal interface?

I have an interface, say;

public interface ICustomCollection<T>
{
     void Add(T item);
     bool Remove(T item);
     bool Contains(T item);
}

I would like to create a class that will access the native C / C ++ dll (which I also create) that provide the implementation. How can I start writing a managed class and native code for this? I know the basics of interoperability, but I don't know how to handle generic types in this context.

+3
source share
2 answers

When you make a small change in your thinking and require that T be the type of interface that comes from Object, and you should, then the C ++ interface becomes much more obvious.

0
source

This works great in Visual Studio 2010:

template<class T>
public interface class ICustomCollection
{
     virtual void Add(T item);
     virtual bool Remove(T item);
     virtual bool Contains(T item);
};

template<class T>
public ref class GenericCustomCollection : ICustomCollection<T>
{
    virtual void Add(T item){ }
    virtual bool Remove(T item){ return false; }
    virtual bool Contains(T item){ return false; }
};

public ref class ConcreteCustomCollection : ICustomCollection<int>
{
public:
    virtual void Add(int item){ }
    virtual bool Remove(int item){ return false; }
    virtual bool Contains(int item){ return false; }
};

, .

++/CLI, : Expert ++/CLI

0

All Articles