これは単純なことかもしれませんが、私の頭はそれを包み込むことを拒否しているので、その場合は常に外の景色が役に立ちます!
患者のパラメータ登録を実装するために、オブジェクト階層を設計する必要があります。これは特定の日に行われ、患者に関するさまざまなパラメータ(血圧、心拍数など)を収集します。これらのパラメーター登録の値は、文字列、整数、浮動小数点数、さらにはGUID(ルックアップリストの場合)など、さまざまなタイプにすることができます。
だから私たちは持っています:
public class ParameterRegistration
{
public DateTime RegistrationDate { get; set; }
public IList<ParameterRegistrationValue> ParameterRegistrationValues { get; set; }
}
public class ParameterRegistrationValue
{
public Parameter Parameter { get; set; }
public RegistrationValue RegistrationValue { get; set; } // this needs to accomodate the different possible types of registrations!
}
public class Parameter
{
// some general information about Parameters
}
public class RegistrationValue<T>
{
public RegistrationValue(T value)
{
Value = value;
}
public T Value { get; private set; }
}
更新:提案のおかげで、モデルは次のようにモーフィングされました。
public class ParameterRegistration
{
public DateTime RegistrationDate { get; set; }
public IList<ParameterRegistrationValue> ParameterRegistrationValues { get; set; }
}
public abstract class ParameterRegistrationValue()
{
public static ParameterRegistrationValue CreateParameterRegistrationValue(ParameterType type)
{
switch(type)
{
case ParameterType.Integer:
return new ParameterRegistrationValue<Int32>();
case ParameterType.String:
return new ParameterRegistrationValue<String>();
case ParameterType.Guid:
return new ParameterRegistrationValue<Guid>();
default: throw new ArgumentOutOfRangeException("Invalid ParameterType: " + type);
}
}
public Parameter Parameter { get; set; }
}
public class ParameterRegistrationValue<T> : ParameterRegistrationValue
{
public T RegistrationValue {get; set; }
}
public enum ParameterType
{
Integer,
Guid,
String
}
public class Parameter
{
public string ParameterName { get; set; }
public ParameterType ParameterType { get; set;}
}
これは確かに少し簡単ですが、ParameterRegistrationのIListが抽象ParameterRegistrationValueオブジェクトを指しているので、実際の値を(サブオブジェクトに格納されているため)どのように取得できるのでしょうか。
たぶん、一般的なこと全体は、結局のところ完全に進む方法ではありません:s