0
我如何可以調用構造函數基地子類構造函數後,沒有在子類構造函數添加額外的代碼?
整個故事:
我有一個基類構造函數通過其子與反射特性的循環。 唯一的問題是它必須在初始化後調用,這發生在子類ctor中。
public class Parent
{
public Parent()
{
DoReflectionStuff();
}
private void DoReflectionStuff()
{
// Do reflection stuff on child's properties
}
}
public class Child : Parent
{
public string Name { get; private set; }
public int Age { get; private set; }
public Child(string Name, int Age) : base()
{
this.Name = Name;
this.Age = Age;
}
}
我不想在調用DoReflectionSuff()
的子控件中添加額外的代碼。
請幫助:)
謝謝
看起來像c#/ .net,但它總是一個好主意,提到這一點。正如威爾指出的那樣 - 你不能。 – Bond 2012-03-20 17:43:01