我只需要显示名称在必填字段列表中的属性。
我正在尝试做这样的事情,但 p.PropertyType.Name == x 不正确:
Pricing pricing = new Pricing();
Type type = typeof(Pricing);
PropertyInfo[] PricingProperties = type.GetProperties();
PricingRequiredFieldDAL requiredField = new PricingRequiredFieldDAL();
var x = requiredField.GetRequiredFields();
var list = PricingProperties.Where(p => p.PropertyType.Name == x);
public class PricingRequiredFieldDAL
{
PricingContext db = new PricingContext();
public List<PricingRequiredField> GetRequiredFields()
{
return db.PricingRequiredFields.Where(p => p.Required == true).ToList();
}
}
我将如何以上述方式使用反射获取我想要的信息?