首页 > 解决方案 > 基于有序字符串列表的过滤对象c#

问题描述

我正在努力过滤从服务返回的数据,我在下面创建了一个虚拟示例。它们是否是仅选择传递到方法中的字段并以与字符串在列表中的相同顺序返回它们的有效方法。

返回所有值的方法一:

GetAll()
{
    ServiceModelResult result = await GetAllFromDatabase(); 

    return result;
}

方法二 - 我们以正确的顺序传入我们希望包含在返回模型中的字段的动态列表:

List<string> fieldsIWantToReturn = new List<string>("FirstName", "CustomerName", "Shop", "ExportPhase")

GetFilteredResults(List<string> fieldsIWantToReturn)
{
    var result = await GetAllFromDatabase();

    //This is the section I don't know how to do.
    var filteredResults =  //do something here to filter - only select the properties defined in the filter class & in the same order

    return filteredResults;
}

标签: c#linq

解决方案


推荐阅读