/// <summary> /// 设置脏属性值 /// </summary> /// <param name="propertyLambda">含类属性的 lambda 表达式</param> /// <param name="newValue">新属性值</param> public void SetDirtyValue(Expression <Func <T, object> > propertyLambda, object newValue) { IsSelfDirty = true; Property property = SelfSheet.GetProperty(this.GetType(), Utilities.GetPropertyInfo <T>(propertyLambda).Name); property.Field.Set(this, newValue); DirtyPropertyNames[property.PropertyInfo.Name] = true; }
/// <summary> /// 设置脏属性值 /// </summary> /// <param name="propertyLambda">含类属性的 lambda 表达式</param> /// <param name="newValue">新属性值</param> public void SetDirtyValue(Expression <Func <T, object> > propertyLambda, object newValue) { IsSelfDirty = true; Property property = SelfSheet.GetProperty(propertyLambda); if (property.Field != null) { property.Field.Set(this, newValue); } else { property.Set(this, newValue); } DirtyPropertyNames[property.PropertyInfo.Name] = true; }
/// <summary> /// 提取脏属性值 /// </summary> protected PropertyValue[] GetDirtValues() { if (_oldPropertyValues == null) { return(null); } List <PropertyValue> result = new List <PropertyValue>(_oldPropertyValues.Count); Sheet targetTable = SelfSheet.GetProperty <T>(p => p.Id).Column.TableColumn.Owner; foreach (KeyValuePair <string, Property> kvp in SelfSheet.GetProperties(this.GetType(), targetTable)) { if (kvp.Value.Column.TableColumn.IsWatermarkColumn) { continue; } if (_oldPropertyValues.TryGetValue(kvp.Key, out object oldValue)) { if (DirtyPropertyNames.TryGetValue(kvp.Key, out bool?isDirty) && isDirty.HasValue) { if (isDirty.Value) { result.Add(new PropertyValue(kvp.Value, oldValue, kvp.Value.Field.GetValue(this))); } } else { object newValue = kvp.Value.Field.GetValue(this); if (!object.Equals(oldValue, newValue)) { result.Add(new PropertyValue(kvp.Value, oldValue, newValue)); } } } } return(result.ToArray()); }