Esempio n. 1
0
        public virtual StateChanges GetChanges
        (
            object oldState,
            object newState,
            Func <FieldInfo, IReadOnlyInstanceTraversalContext, bool> fieldIgnoreFunc       = null,
            Func <PropertyInfo, IReadOnlyInstanceTraversalContext, bool> propertyIgnoreFunc = null
        )
        {
            var changes = new StateChanges
            {
                OldState = oldState,
                NewState = newState
            };

            //
            // both null?
            //
            if (oldState == null && newState == null)
            {
                // no changes, obviously
                return(changes);
            }

            //
            // same instance?
            //
            if (oldState != null && oldState.Equals(newState))
            {
                // no changes, obviously
                return(changes);
            }

            //
            // different types?
            //
            if (oldState != null && newState != null && oldState.GetType() != newState.GetType())
            {
                throw new NotSupportedException($"Finding changes between two different classes is not supported. Received: old={oldState.GetType().FullName}, new={newState.GetType().FullName}");
            }

            //
            // ok, time to work
            //
            worker.FindDifferences(oldState, newState, changes, MaxDepth, fieldIgnoreFunc, propertyIgnoreFunc);

            return(changes);
        }
Esempio n. 2
0
        public virtual StateChanges GetChanges(object oldState, object newState)
        {
            var changes = new StateChanges
            {
                OldState = oldState,
                NewState = newState
            };

            //
            // both null?
            //
            if (oldState == null && newState == null)
            {
                // no changes, obviously
                return(changes);
            }

            //
            // same instance?
            //
            if (oldState != null && oldState.Equals(newState))
            {
                // no changes, obviously
                return(changes);
            }

            //
            // different types?
            //
            if (oldState != null && newState != null && oldState.GetType() != newState.GetType())
            {
                throw new NotSupportedException($"Finding changes between two different classes is not supported. Received: old={oldState.GetType().FullName}, new={newState.GetType().FullName}");
            }

            //
            // ok, time to work
            //
            worker.FindDifferences(oldState, newState, changes, MaxDepth);

            return(changes);
        }