/// <summary> /// 复制自己 /// </summary> /// <returns>复制结果</returns> public GeneralObject Clone() { GeneralObject go = new GeneralObject(); go.CopyFrom(this); return(go); }
private static void OnDefaultObjectChanged(object o, DependencyPropertyChangedEventArgs e) { PropertySetter ps = (PropertySetter)o; if (ps.Object != null) { //默认值改变了,但是对象还没有值,给对象设置值为默认值 if (ps.Object.GetPropertyValue(ps.PropertyName) == null) { if (ps.DefaultObject is GeneralObject) { //复制默认对象到新对象 GeneralObject go = ps.DefaultObject as GeneralObject; GeneralObject ngo = new GeneralObject(); ngo.CopyFrom(go); ps.Object.SetPropertyValue(ps.PropertyName, ngo, false, true); } else if (ps.DefaultObject is ObjectList) { //复制默认对象到新对象 ObjectList go = ps.DefaultObject as ObjectList; ObjectList ngo = new ObjectList(); ngo.CopyFrom(go); ps.Object.SetPropertyValue(ps.PropertyName, ngo, false, true); } } } }
public void NewPropertyValue(string propertyName) { //有属性默认值 var p = (from ps in PropertySetters where ps.PropertyName == propertyName select ps).FirstOrDefault(); if (p != null && p.Default != null) { //设置默认属性结果 SetPropertyValue(propertyName, p.Default, true, true); //如果默认属性是列表,调用列表的New过程 if (p.Default is BaseObjectList) { (p.Default as BaseObjectList).New(); } } //有默认对象,复制默认对象 else if (p != null && p.DefaultObject != null) { if (p.DefaultObject is GeneralObject) { //复制默认对象到新对象 GeneralObject go = p.DefaultObject as GeneralObject; GeneralObject ngo = new GeneralObject(); ngo.CopyFrom(go); p.Object.SetPropertyValue(p.PropertyName, ngo, false, true); } else if (p.DefaultObject is ObjectList) { //复制默认对象到新对象 ObjectList go = p.DefaultObject as ObjectList; ObjectList ngo = new ObjectList(); ngo.CopyFrom(go); p.Object.SetPropertyValue(p.PropertyName, ngo, false, true); } } else { //如果属性是集合 if (GetProperty(propertyName).PropertyType == typeof(BaseObjectList)) { //如果属性存在,清空集合 BaseObjectList old = (BaseObjectList)this.GetPropertyValue(propertyName); if (old != null) { old.New(); } //否则,无不置空标记,设置一个空集合 else if (!NotEmpty) { SetPropertyValue(propertyName, new ObjectList(), true); } } else { SetPropertyValue(propertyName, null, true, true); } } }
/// <summary> /// 当数据源发生变化时,复制数据源中的属性到本对象。 /// </summary> /// <param name="dp">代表对象自身</param> /// <param name="args">改变的新值为获取数据的源</param> public static void OnSourceChanged(DependencyObject dp, DependencyPropertyChangedEventArgs args) { GeneralObject edit = (GeneralObject)dp; GeneralObject source = args.NewValue as GeneralObject; if (source == null) { return; } edit.CopyFrom(source); //对象变为未修改,不是新的 edit.IsNew = false; edit.IsModified = false; }
public void ToSource() { //如果Source不为空,把数据复制到Source中 if (Source != null) { Source.CopyFrom(this); } //如果有对应列表,复制一份到列表中 else if (List != null) { GeneralObject go = new GeneralObject(); go.CopyFrom(this); List.Add(go); } }
public void CopyDataFrom(GeneralObject go) { //复制实体类型 if (go.entityType != null) { EntityType = go.EntityType; } foreach (string key in go._customPropertyValues.Keys) { object value = go._customPropertyValues[key]; //是列表,进行列表复制 if (value is BaseObjectList) { //如果列表不存在,新建列表 if (!_customPropertyValues.ContainsKey(key) || _customPropertyValues[key] == null) { ObjectList ol = new ObjectList(); SetPropertyValue(key, ol, true); } ObjectList nol = (ObjectList)_customPropertyValues[key]; nol.CopyFrom(value as BaseObjectList); } //是对象,进行对象复制 else if (value is GeneralObject) { GeneralObject newgo = new GeneralObject(); newgo.CopyFrom((GeneralObject)value); SetPropertyValue(key, newgo, true); } //是一般属性,调用设置属性值的过程 else { this.NewGetType(); SetPropertyValue(key, value, true); } } }
/// <summary> /// 根据名称,查找所有资源 /// </summary> /// <param name="name"></param> /// <returns></returns> public object FindResource(string name) { //如果是left,返回当前左侧数据 if (name == "left") { GeneralObject go = new GeneralObject(); go.CopyFrom(CurrentLeft); return go; } else if (name == "head") { GeneralObject go = new GeneralObject(); go.CopyFrom(CurrentHead); return go; } else if (name == "each") { GeneralObject go = new GeneralObject(); go.CopyFrom(CurrentMain); return go; } else { //在主体数据中查询资源 foreach (BodyDatas item in TableBodyItems) { if (item.Name == name) { return item.Value; } } } //调用框架的查找资源 return FrameworkElementExtension.FindResource(this,name); }
/// <summary> /// 复制自己 /// </summary> /// <returns>复制结果</returns> public GeneralObject Clone() { GeneralObject go = new GeneralObject(); go.CopyFrom(this); return go; }