【发布时间】:2010-11-01 15:08:47
【问题描述】:
假设我们有这两个类:
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 的构造函数中使用反射的某种方式?
【问题讨论】:
标签: c# reflection inheritance types