派生クラスの基本プロパティを設定する最善の方法を教えてくれる人がいるかどうか疑問に思っています。ベースが使用されているか子が使用されているかに関係なく、1 つのメソッドを使用してベースのプロパティを設定したいと思います。
これが私が尋ねていることの例です:
public class Parent
{
public string Id {get; set;}
}
public class Child : Parent
{
public string Name {get; set;}
}
public Parent GetParent(int ID)
{
Parent myParent = new Parent();
//Lookup and populate
return Parent;
}
public Child GetChild(string name)
{
Child myChild = new Child();
//Use the GetParent method to populate base items
//and then
//Lookup and populate Child properties
return myChild;
}