Esempio n. 1
0
            public DeclarationsGenerator(TrustedType type, string generatedClassName)
            {
                ArrayList list = new ArrayList();

                list.Add(new ConstructorGenerator(type, generatedClassName));

                if (type.IsAbstract)
                {
                    TrustedMethodInfo[] methodInfos = type.GetMethods(flags);
                    if (methodInfos != null)
                    {
                        foreach (TrustedMethodInfo method in methodInfos)
                        {
                            // PropertyGenerators will be created in the next step.  Don't add them here.
                            if (!method.Name.Contains("get_") && !method.Name.Contains("set_") &&
                                MethodNeedsOverride(method, type))
                            {
                                list.Add(new MethodGenerator(method));
                            }
                        }
                    }

                    TrustedPropertyInfo[] properties = type.GetProperties(flags);
                    if (properties != null)
                    {
                        foreach (TrustedPropertyInfo property in properties)
                        {
                            TrustedMethodInfo get = property.GetGetMethod();
                            TrustedMethodInfo set = property.GetSetMethod();

                            if (MethodNeedsOverride(get, type) || MethodNeedsOverride(set, type))
                            {
                                list.Add(new PropertyGenerator(property));
                            }
                        }
                    }
                }

                methods = new MethodGeneratorBase[list.Count];
                list.CopyTo(methods);
            }
Esempio n. 2
0
        private static bool DeepEquals(object obj1, object obj2, bool skipUnimportant)
        {
            if (object.ReferenceEquals(obj1, obj2))
            {
                // Shortcut- if they are the same object, return true;
                return(true);
            }
            Type type1 = obj1.GetType();
            Type type2 = obj2.GetType();

            if (type1 != type2)
            {
                return(false);
            }
            if (type1 == typeof(string))
            {
                return(obj1.ToString() == obj2.ToString());
            }

            bool        equals;
            TrustedType trustedType = PT.Trust(type1);

            TrustedPropertyInfo[] properties = trustedType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (TrustedPropertyInfo property in properties)
            {
                if (skipUnimportant)
                {
                    // If we don't care about the property (declared by Freezable or its ancestors), skip it!
                    if (IsPropertyDeclaredByAncestorsOf(PT.Untrust(property.DeclaringType), typeof(Freezable)) ||
                        IsPropertyDeclaredByAncestorsOf(PT.Untrust(property.DeclaringType), typeof(FrameworkElement)))
                    {
                        continue;
                    }
                }
                if (IsPropertyProblematic(property))
                {
                    continue;
                }
                if (property.Name == "Item")
                {
                    if (obj1 is IEnumerable)
                    {
                        equals = DeepEquals((IEnumerable)obj1, (IEnumerable)obj2, skipUnimportant);
                    }
                    else
                    {
                        // This is an indexer.  We can't really compare it.
                        equals = true;
                    }
                }
                else
                {
                    object value1 = property.GetValue(obj1, null);
                    object value2 = property.GetValue(obj2, null);

                    if (property.PropertyType.IsValueType)
                    {
                        switch (property.PropertyType.Name)
                        {
                        case "Double": equals = MathEx.AreCloseEnough((double)value1, (double)value2); break;

                        case "Point": equals = MathEx.AreCloseEnough((Point)value1, (Point)value2); break;

                        case "Vector": equals = MathEx.AreCloseEnough((Vector)value1, (Vector)value2); break;

                        case "Rect": equals = MathEx.AreCloseEnough((Rect)value1, (Rect)value2); break;

                        case "Matrix": equals = MathEx.AreCloseEnough((Matrix)value1, (Matrix)value2); break;

                        case "Point3D": equals = MathEx.AreCloseEnough((Point3D)value1, (Point3D)value2); break;

                        case "Point4D": equals = MathEx.AreCloseEnough((Point4D)value1, (Point4D)value2); break;

                        case "Quaternion": equals = MathEx.AreCloseEnough((Quaternion)value1, (Quaternion)value2); break;

                        case "Vector3D": equals = MathEx.AreCloseEnough((Vector3D)value1, (Vector3D)value2); break;

                        case "Rect3D": equals = MathEx.AreCloseEnough((Rect3D)value1, (Rect3D)value2); break;

                        case "Matrix3D": equals = MathEx.AreCloseEnough((Matrix3D)value1, (Matrix3D)value2); break;

                        default: equals = object.Equals(value1, value2); break;
                        }
                    }
                    else
                    {
                        equals = DeepEquals(value1, value2, skipUnimportant);
                    }
                }
                if (!equals)
                {
                    return(false);
                }
            }
            return(true);
        }