私がこのようなコードを持っているとしましょう:
public class Base // I cannot change this class
{
public string Something { get; private set; }
public string Otherthing { get; set; }
public static Base StaticPreSet
{
get { return new Base { Something = "Some", Otherthing = "Other"}; }
}
public static Base StaticPreSet2
{
get { return new Base { Something = "Some 2", Otherthing = "Other 2"}; }
}
}
public class SubClass : Base // I can change this class all I want.
{
public string MoreData { get; set; }
// How can I wrap the PreSets here so that they return SubClass objects?
// Something like this:
public static SubClass MyWrappedPreset
{
get
{
// Code here to call the base preset and then use it as the
// base of my SubClass instance.
}
}
}
これを複雑にしているのは、Somethingプロパティです。プライベートセッターがあります。そのため、サブクラスに設定することはできません。設定できる唯一の方法は、プリセットプロパティを使用することです。
サブクラスタイプのオブジェクトを返すように、サブクラスのStaticPreSetプロパティをラップする方法はありますか?