I'm building a few bits and pieces in C# (xna) at the moment, and coming from a c++ background and having a few issues with the lack of multiple inheritance combined with a lack of macros.
I need a number of singleton instances for the game managers etc, and would like to use a base generic class to do this:
class Singleton<T> where T : new(){ public T GetInstance { get { lock(padlock) { if( m_instance == null ) { m_instance = new T(); } return m_instance; } } } private static T m_instance; private static readonly object padlock = new object()}
So then I can create my singleton instances like this:
class MyClass : Singleton<MyClass> { ... }
Of course that means that I'm prevented from inheriting from any other classes. I guess I could get around it by having my singleton instances only inherit from the singleton class, but if anyone can think of a fancy way of getting around it I'm all ears :)