문제

I'm currently storing a list of Tests with associated information, including database IDs, inside static variables in my code. Here's an example:

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");
}

These then get used to create a test group through other static properties get methods:

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
                       });
        }
    }
}

The problem I'm having now is there is essentially no way to lookup the MyopathologyTest for a specific ID. One solution would be to create a dictionary and manually insert all these tests into the dictionary with the ID as the key. This seems like repeating a lot of code though.

What is the proper way to be implementing something like this? I'm thinking I need to externalize the test data, load in the tests during runtime and generate the proper look-up tables and groups on the fly. Is this the right approach I should be looking at or is there a better way?

도움이 되었습니까?

해결책

Why not keep the test information in a database, like SQLite, and fetch the data on an as-needed basis using ADO.NET libraries? Response time is virtually instantaneous, so you have no need to store many test objects in a dictionary.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top