I have this class, that implements the singleton pattern, and a subclass.
public class Base{
public static Base Instance;
static Base()
{
System.Type myType = MethodInfo.GetCurrentMethod().DeclaringType;
Instance = (Base)Activator.CreateInstance(myType);
}
public void ID()
{
MessageBox.Show("I am " + this.GetType().Name);
}
}
public class Sub : Base{
}
When I call Base.Instance.ID(), I get "I am Base", which is what I want.
When I call Sub.Instance.ID(), I also get "I am Base". This makes sense,
since MethodInfo.GetCurrentMethod().DeclaringType SHOULD return Base, since that's where it's declared.
The question is - is there any way to tell, when Base's static constructor is called - which object I am, in fact, instantiating? Or, since it's static, there really isn't any Sub object to get info from?
