示例#1
0
        private void VerifyCloneForFreezable(Freezable frozenObject)
        {
            if (frozenObject == null)
            {
                return;
            }

            TrustedType       type   = PT.Trust(frozenObject.GetType());
            TrustedMethodInfo method = type.GetMethod("Clone", BindingFlags.Public | BindingFlags.Instance);

            if (method == null)
            {
                throw new ApplicationException("Could not find Clone method on " + type.Name);
            }

            Freezable copy = (Freezable)method.Invoke(frozenObject, null);

            if (!ObjectUtils.DeepEqualsToAnimatable(frozenObject, copy))
            {
                AddFailure("{0}.Copy failed to produce an exact copy", type.Name);
            }

            method = type.GetMethod("CloneCurrentValue", BindingFlags.Public | BindingFlags.Instance);
            if (method == null)
            {
                throw new ApplicationException("Could not find CloneCurrentValue method on " + type.Name);
            }

            copy = (Freezable)method.Invoke(frozenObject, null);

            if (!ObjectUtils.DeepEqualsToAnimatable(frozenObject, copy))
            {
                AddFailure("{0}.CloneCurrentValue failed to produce an exact copy", type.Name);
            }
        }
示例#2
0
        private static bool CompareFreezables(Freezable firstFreezable, Freezable secondFreezable, int depth)
        {
            if (firstFreezable == null && secondFreezable == null)
            {
                return(true);
            }
            if (firstFreezable == null || secondFreezable == null || firstFreezable.GetType() != secondFreezable.GetType())
            {
                return(false);
            }
            IEnumerator enumerator1 = (IEnumerator)firstFreezable.GetLocalValueEnumerator();
            IEnumerator enumerator2 = (IEnumerator)secondFreezable.GetLocalValueEnumerator();

            while (enumerator1.MoveNext())
            {
                if (!enumerator2.MoveNext() || !PropertyUtilities.Compare(enumerator1.Current, enumerator2.Current, depth + 1))
                {
                    return(false);
                }
            }
            return(!enumerator2.MoveNext());
        }