P
puzzlecracker
Hello,
That's pretty crazy requirement -- I would like to find out whether I
can find a name of derived class in the base class method/ctor for
reflection purposes.
public abstract class Base
{
void Foo(){ string derivedClassName=/* Name of the class
called via it's instance*/; }
}
Public class DerivedA:Base
{
}
Public class DerivedB: Base
{
}
void Test()
{
DerivedB d=new DerivedB();
Base d2=new DerivedB();
d.Foo(); // I want derivedClassName to best set to DerivedB
}
Same way for constructor -- To know which derived class called base
class constructor.
Is it even possible? What's the workaround, as I am sure it's a fairly
common problem in a framework/Library design.
Thanks
That's pretty crazy requirement -- I would like to find out whether I
can find a name of derived class in the base class method/ctor for
reflection purposes.
public abstract class Base
{
void Foo(){ string derivedClassName=/* Name of the class
called via it's instance*/; }
}
Public class DerivedA:Base
{
}
Public class DerivedB: Base
{
}
void Test()
{
DerivedB d=new DerivedB();
Base d2=new DerivedB();
d.Foo(); // I want derivedClassName to best set to DerivedB
}
Same way for constructor -- To know which derived class called base
class constructor.
Is it even possible? What's the workaround, as I am sure it's a fairly
common problem in a framework/Library design.
Thanks