0

I'm trying to convert an project from C++ to C# but in the C++ version the following code is used:

std::list<PlayerBase*>& AllPlayers = AutoList<PlayerBase>::GetAllMembers();

And AutoList is just a header file with the folowwing

#ifndef AUTOLIST_H
#define AUTOLIST_H
#include <list>

template <class T>
class AutoList
{
public:

    typedef std::list<T*> ObjectList;

private:

    static ObjectList m_Members;

protected:

    AutoList()
    {
        //cast this object to type T* and add it to the list
        m_Members.push_back(static_cast<T*>(this));
    }

    ~AutoList()
    {
        m_Members.remove(static_cast<T*>(this));
    }

public:

    static ObjectList& GetAllMembers(){return m_Members;}
};

template <class T>
std::list<T*> AutoList<T>::m_Members;

#endif

So how can I make an C# class that can do the same for me, which is selecting all the objects of the class type: PlayerBase?

Kiwi
  • 2,713
  • 7
  • 44
  • 82
  • I think we'll need to address this at a higher level... What does this need to do? You have a list of `object` types, and you want to select from that list all the objects that are of underlying type `PlayerBase`? Is that right? – Matthew Watson May 19 '13 at 15:18
  • 1
    maybe Linq is what you are looking for: http://stackoverflow.com/questions/1184944/linq-from-a-list-of-type-t-retrieve-only-objects-of-a-certain-subclass-s – thalm May 19 '13 at 15:26
  • Oh no it didn't work, I tried with this program but no results are shown prgram used for testing: http://pastebin.com/6Cwmn6Fz – Kiwi May 20 '13 at 10:51

0 Answers0