我有以下方法:
string fieldName = "dateAdded";
public void assignData(IEnumerable<object> enumerable) {
foreach (dynamic customData in enumerable) {
try {
// what I need: if(customData.[fieldName] == DateTime.Now)
if(customData.dateAdded == DateTime.Now)
customData.dateAdded = newValue;
}
} catch {
}
}
}
我需要传递一个字段名称并检查它是否与 DateTime.Now 匹配。我怎样才能做到这一点?谢谢!