Is there any direct way to determine if a method in a base class (not an abstract) is called by a derived class or explicitly from somewhere that has created an instance of base class?
The simplest method is to use reflection:
public virtual void MyBaseClassMethod()
{
var currType = this.GetType();
if (currType == typeof(MyBaseClass))
{
// base class instantiated directly.
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With