コード例 #1
0
        /// <summary>
        /// 用 usageObject 中属性的值,更新 sourceObject
        /// </summary>
        /// <param name="sourceObject"></param>
        /// <param name="usageObject"></param>
        public static void Update(object sourceObject, object usageObject)
        {
            if (sourceObject == null || usageObject == null)
            {
                return;
            }

            SnapshotMemberCollection members = new SnapshotMemberCollection();

            foreach (ObjectCompareResult result in ObjectCompare.Compare(sourceObject, usageObject))
            {
                members.Add(result.MemberName, result.SourceValue, result.CompareValue);
            }

            foreach (SnapshotMember member in members)
            {
                member.SetMember(sourceObject, SnapshotMember.EnumMemberValue.NewValue);
            }
        }
コード例 #2
0
        /// <summary>
        /// 撤销对传入的 obj 对象的所有更改
        /// 还原之后会把快照给清除掉
        /// </summary>
        public void Revert()
        {
            if (_mirrorObject == null || _object == null)
            {
                return;
            }

            SnapshotMemberCollection members = new SnapshotMemberCollection();

            foreach (ObjectCompareResult result in ObjectCompare.Compare(_mirrorObject, _object))
            {
                members.Add(result.MemberName, result.SourceValue, result.CompareValue);
            }

            foreach (SnapshotMember member in members)
            {
                member.SetMember(_object, SnapshotMember.EnumMemberValue.OldValue);
            }

            _mirrorObject = null;
        }