public class ConflictSaver
{
private readonly IEnumerable<CommonJobDataInfo> _conflictingJobData;
private readonly DataAccessDataContext _dc;
public ConflictSaver(IEnumerable<CommonJobDataInfo> conflictingJobData, DataAccessDataContext dc)
{
_conflictingJobData = conflictingJobData;
_dc = dc;
}
public void Save()
{
foreach (var data in _conflictingJobData)
{
var type = data.ClientBaseObject.GetType();
var formattedProperty = data.Property.Trim('.').ToUpper();
foreach (var property in type.GetProperties())
{
var currentProperty = data.ClientBaseObject.GetType().GetProperties().First(t => t.Name.Trim() == property.Name.Trim());
if(currentProperty.Name.ToUpper()== formattedProperty)
{
if (data.UseServerValue)
currentProperty.SetValue(currentProperty, data.ServerValue, null);
else
currentProperty.SetValue(currentProperty, data.ClientValue, null);
}
}
}
}
}
当我尝试调用 SetValue() 时,我得到Object 与 Save() 函数中的目标类型不匹配。我反省时发臭。