假设我们有以下两个类:
public class Derived : Base
{
public Derived(string s)
: base(s)
{ }
}
public class Base
{
protected Base(string s)
{
}
}
我怎样才能从内部的构造函数中找出Base那Derived是调用?这是我想出的:
public class Derived : Base
{
public Derived(string s)
: base(typeof(Derived), s)
{ }
}
public class Base
{
protected Base(Type type, string s)
{
}
}
还有另一种不需要传递的方法typeof(Derived),例如,某种使用Base构造函数中的反射的方法吗?
Derived1 d1 = new Base();