我正在尝试访问我通过产品ID获取的产品的自定义属性,但我真的不知道该怎么做。
所以,如果我像这样抓住产品:
var product = _productService.GetProductByIds(productId);
我想用if语句访问这些属性:
product.CustomProperties.Keys.Contains("Popular")
似乎无法在此找到任何东西,任何人都可以帮忙吗?
首先,GetProductById
s返回产品列表,也许您打算只获得一个产品。因此,请改用GetProductById。
此外,没有像“热门”内部产品模型,可能你已经添加了自定义。
最后,我假设你想检查产品模型中是否存在该属性!这可以做如下,
var product = _productService.GetProductById(productId);
var productProperty = product.GetType().GetProperty("Sku");
if(productProperty != null)
{
//exists
}
else
{
//doesn't exists
}