0

ユーザーがオブジェクトの別のフィールドを検索できるリポジトリ クラスを実装する必要があります。別のサービスからデータを取得した後、結果をDictionaryオブジェクトに保存します。今度は、さまざまなオブジェクトのプロパティに基づいて結果をフィルターできるようにしたいと考えています。例えば:

People {
    public string FirstName {get; set;}
    public string LastName {get; set;}
}

Dictionary<int, People> rawData;

public List<People> GetByFirstName(string firstName) {
    if(string.IsNullOrEmpty(firstName)) {
         return new List<People>();
    }
    return rawData.Where(p => p.FirstName == firstName).ToList(i => i.Value);
}

public List<People> GetByLastName(string lastName) {
    if(string.IsNullOrEmpty(lastName)) {
         return new List<People>();
    }
    return rawData.Where(p => p.LastName == lastName).ToList(i => i.Key, i => i.Value);
}

ここで、ヘルパー関数を使用してある種のプロトタイプ パターンを実装したいと思います。

public List<People> SearchHelper(string searchValue, //need to change so that another can pass condition in here) {
    if(string.IsNullOrEmpty(lastName)) {
         return new List<People>();
    }
    return rawData.Where(// need to put customize condition here).ToList(i => i.Value);
}

オブジェクトのプロパティが大量にあるため、ここにプロトタイプ パターンが必要な理由。任意の提案をいただければ幸いです。

4

0 に答える 0