/// <summary> /// Serializes the object using specified etalon. /// </summary> /// <param name="obj">The object to serialize.</param> /// <param name="diff">The etalon object.</param> public void Write(IFRSerializable obj, object diff) { if (obj == null) { return; } XmlItem saveCurItem = FCurItem; XmlItem saveCurRoot = FCurRoot; StringBuilder saveText = FText; object saveDiffObject = FDiffObject; bool destroyDiffObject = false; try { FText = new StringBuilder(); FCurItem = FCurItem == null ? FRoot : FCurItem.Add(); FCurRoot = FCurItem; FDiffObject = diff; if (obj is Base && SerializeTo == SerializeTo.Preview) { FDiffObject = (obj as Base).OriginalComponent; FCurItem.Name = FDiffObject != null ? (obj as Base).Alias : (obj as Base).ClassName; } if (GetDiff != null) { DiffEventArgs e = new DiffEventArgs(); e.Object = obj; GetDiff(this, e); FDiffObject = e.DiffObject; } if (FDiffObject == null) { try { FDiffObject = Activator.CreateInstance(obj.GetType()); destroyDiffObject = true; } catch { } } obj.Serialize(this); } finally { if (FText.Length > 0) { FText.Remove(FText.Length - 1, 1); } FCurRoot.Text = FText.ToString(); FText = saveText; FCurItem = saveCurItem; FCurRoot = saveCurRoot; if (destroyDiffObject && FDiffObject is IDisposable) { (FDiffObject as IDisposable).Dispose(); } FDiffObject = saveDiffObject; } }
/// <summary> /// Serializes the object using specified etalon. /// </summary> /// <param name="obj">The object to serialize.</param> /// <param name="diff">The etalon object.</param> public void Write(IFRSerializable obj, object diff) { if (obj == null) { return; } XmlItem saveCurItem = curItem; XmlItem saveCurRoot = curRoot; //StringBuilder saveText = FText; object saveDiffObject = diffObject; try { //FText = new StringBuilder(); curItem = curItem == null ? root : curItem.Add(); curRoot = curItem; diffObject = diff; if (obj is Base && SerializeTo == SerializeTo.Preview) { diffObject = (obj as Base).OriginalComponent; curItem.Name = diffObject != null ? (obj as Base).Alias : (obj as Base).ClassName; } if (GetDiff != null) { DiffEventArgs e = new DiffEventArgs(); e.Object = obj; GetDiff(this, e); diffObject = e.DiffObject; } if (diffObject == null) { try { Type objType = obj.GetType(); if (!diffObjects.Contains(objType)) { diffObjects[objType] = Activator.CreateInstance(objType); } diffObject = diffObjects[objType]; } catch { } } obj.Serialize(this); } finally { //if (FText.Length > 0) // FText.Remove(FText.Length - 1, 1); //FCurRoot.Text = FText.ToString(); //FText = saveText; curItem = saveCurItem; curRoot = saveCurRoot; diffObject = saveDiffObject; } }