以下の構造のような非ジェネリック クラスから継承するジェネリック クラスを用意します。
public class Result
{
public string ErrorCode { get; set;}
public string ErrorMessage { get; set;}
public boo Success { get; set;}
//Lots more properties
public ClientResult ToClientResult()
{
//some pretty involved calculations of error coded and status
}
}
public class Result<T> : Result
{
public T details {get; set;}
public ClientResult<T> ToClientResult<T>()
{
//Need to call the parent class implementation and convert result to generic ver
}
}
私の質問は、親ToClientResult()
を呼び出して結果を汎用バージョンに変換する方法です。次に、のプロパティをクラスの詳細プロパティにClientResult<T>
設定する必要があります。ClientResult<T>
Result<T>
ここで簡単な解決策が欠けていると確信しています。親クラスのロジックはかなり複雑なので、複製したくありません。