【发布时间】:2019-09-26 13:34:17
【问题描述】:
我有课
[BsonIgnoreExtraElements]
public class CustomerModel
{
public string BranchID { get; set; }
public string BranchName { get; set; }
public string ReceiverID { get; set; }
public string ReceiverName{ get; set; }
}
我正在编写一个过滤器活动,它可以验证任何在 MongoDB 中配置的具有特定值的字段
"Exclude":[{"SourceCol":"Receiver Mode ID","Values":{"Value":["G","8","J"]}}
并将比较逻辑写为
public static object GetPropValue(object src, string propName)
{
return src.GetType().GetProperty(propName).GetValue(src, null);
}
public static bool CheckPropertyCompare(CustomerModel customer, Exclude item)
{
var propertyValue = GetPropValue(customer, item.SourceCol);
return item.Values.Value.ToList().Contains(propertyValue);
}
在此,来自 MongoDB 的 Receiver Mode ID 实际上正在寻找 ReceiverID,我不知道如何解决这个问题。我能想到的唯一选择是键值对集合来获取字段名称。但想知道是否有像属性这样的选项可以简化这个过程。
TIA
【问题讨论】:
标签: c# .net mongodb reflection