我目前正在我的代码中的静态变量中存储一个包含相关信息(包括数据库ID)的测试列表。这是一个例子:
public static class IsokineticTests
{
// Cervical Spine Group
public static MyopathologyTest NeckFlexors = MyopathologyTest.Create(600, "Neck Flexors");
public static MyopathologyTest AnteriorObliques = MyopathologyTest.Create(601, "Anterior Obliques");
public static MyopathologyTest NeckExtensors = MyopathologyTest.Create(602, "Neck Extensors");
public static MyopathologyTest PosteriorObliques = MyopathologyTest.Create(603, "Posterior Obliques");
public static MyopathologyTest LateralFlexion = MyopathologyTest.Create(604, "Lateral Flexion");
// Shoulder Group
public static MyopathologyTest ShoulderAbductors = MyopathologyTest.Create(610, "Shoulder Abductors");
public static MyopathologyTest ShoulderExtensors = MyopathologyTest.Create(611, "Shoulder Extensors");
public static MyopathologyTest ShoulderFlexors = MyopathologyTest.Create(612, "Shoulder Flexors");
public static MyopathologyTest ShoulderLateralRotators = MyopathologyTest.Create(613, "Shoulder Lateral Rotators");
public static MyopathologyTest ShoulderMedialRotators = MyopathologyTest.Create(614, "Shoulder Medial Rotators");
}
然后用于通过其他静态属性获取方法创建测试组:
public static class IsokineticTestGroups
{
public static IsokineticTestGroup CervicalSpine
{
get
{
return IsokineticTestGroup.Create("Cervical Spine",
new List<MyopathologyTest>
{
IsokineticTests.NeckFlexors,
IsokineticTests.AnteriorObliques,
IsokineticTests.NeckExtensors,
IsokineticTests.PosteriorObliques,
IsokineticTests.LateralFlexion
});
}
}
}
我现在遇到的问题是基本上没有办法查找特定ID的MyopathologyTest。一种解决方案是创建字典并手动将所有这些测试插入字典中,并将ID作为密钥。这似乎重复了很多代码。
实现这样的事情的正确方法是什么?我认为我需要外化测试数据,在运行时加载测试并生成正确的查找表和组在飞行中。这是我应该看的正确方法还是有更好的方法?
答案 0 :(得分:2)
为什么不将测试信息保存在SQLite等数据库中,并使用ADO.NET库根据需要获取数据?响应时间几乎是瞬时的,因此您无需在字典中存储许多测试对象。</ p>