이것은 간단 할 수도 있지만 내 머리를 감싸는 것을 거부하기 때문에 외부보기가 항상 유용합니다!일반 구조를 사용하는 C# 클래스 디자인
환자를위한 매개 변수 등록을 구현하려면 개체 계층 구조를 설계해야합니다. 이것은 특정 날짜에 발생하며 환자 (혈압, 심장 박동수 등)에 대한 다양한 매개 변수를 수집합니다. 매개 변수 등록의 값은 문자열, 정수, 부동 소수점 또는 지침 (조회 목록 용)과 같은 다른 유형이 될 수 있습니다.
그래서 우리가 가진 :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; }
}
UPDATE : 감사는 제안에, 모델은 지금으로 변신 한 다음
참으로 조금 더 간단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는
그리고 무엇이 공개적인 fied를 사용하고 있습니까? –
문제가 무엇인지 언급하지 않았습니다. –
여기에 당신이 누락 된 것은 무엇입니까? 작동하지 않습니까? 어디에서/어떻게 실패합니까? –