我正在努力过滤从服务返回的数据,下面创建了一个虚拟示例。它们是仅选择传递给方法的字段并以列表中字符串的相同顺序返回它们的有效方法。
一种返回所有值的方法:
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;
}