【发布时间】:2019-12-27 16:17:28
【问题描述】:
我想使用 filterType 参数来定义 Stock 对象上要过滤的属性。
[HttpGet("{searchText}/{filterType}")]
public async Task<ActionResult<List<Stock>>> Get(string searchText, string filterType)
{
List<Stock> v = await this._context.StockView.Where(w => w.[filterType] == searchText).ToListAsync();
return this.Ok(v);
}
有没有办法做到这一点,我可以使用字符串参数来定义对象上的属性来限制?
【问题讨论】:
-
你试过反射吗?