Let's say we've got these two classes:
public class Derived : Base
{
public Derived(string s)
: base(s)
{ }
}
public class Base
{
protected Base(string s)
{
}
}
How can I find out from within the ctor of Base that Derived is the invoker? This is what I came up with:
public class Derived : Base
{
public Derived(string s)
: base(typeof(Derived), s)
{ }
}
public class Base
{
protected Base(Type type, string s)
{
}
}
Is there another way that doesn't require passing typeof(Derived), e.g. some way of using reflection from within Base's ctor?