Esempio n. 1
0
        internal static bool EqualsByValueInternal(this IComposite self, IComposite other, IDictionary<IComposite, object> path)
        {
            if (self == null && other == null) return true;
            if (self == null || other == null) return false;

            if (self.GetMembers().Count() != other.GetMembers().Count())
            {
                return false;
            }

            path.Add(self, null);

            foreach (var member in self.GetMembers())
            {
                var value = self.GetProperty(member);
                var otherValue = other.GetProperty(member);

                var composite = value as IComposite;
                if (composite != null && path.ContainsKey(composite)) continue; // prevent circular refs

                var otherComposite = otherValue as IComposite;
                // Composite property
                if (composite != null && otherComposite != null && !composite.EqualsByValueInternal(otherComposite, path))
                {
                    return false;
                }
                var compositeList = value as IEnumerable<IComposite>;
                var otherCompositeList = otherValue as IEnumerable<IComposite>;
                // Composite list
                if (compositeList != null && otherCompositeList != null)
                {
                    if (compositeList.Count() != otherCompositeList.Count())
                    {
                        return false;
                    }
                    for (var i = 0; i < compositeList.Count(); i++)
                    {
                        var item = compositeList.ElementAt(i);
                        if (path.ContainsKey(item)) continue; // prevent circular refs
                        if (!item.EqualsByValueInternal(otherCompositeList.ElementAt(i), path)) return false;
                    }
                }
                // Simple property
                if (composite == null && compositeList == null && !Equals(value, otherValue))
                {
                    return false;
                }
            }
            return true;
        }
Esempio n. 2
0
        internal static bool EqualsByValueInternal(this IComposite self, IComposite other, IDictionary <IComposite, object> path)
        {
            if (self == null && other == null)
            {
                return(true);
            }
            if (self == null || other == null)
            {
                return(false);
            }

            if (self.GetMembers().Count() != other.GetMembers().Count())
            {
                return(false);
            }

            path.Add(self, null);

            foreach (var member in self.GetMembers())
            {
                var value      = self.GetProperty(member);
                var otherValue = other.GetProperty(member);

                var composite = value as IComposite;
                if (composite != null && path.ContainsKey(composite))
                {
                    continue;                                                   // prevent circular refs
                }
                var otherComposite = otherValue as IComposite;
                // Composite property
                if (composite != null && otherComposite != null && !composite.EqualsByValueInternal(otherComposite, path))
                {
                    return(false);
                }
                var compositeList      = value as IEnumerable <IComposite>;
                var otherCompositeList = otherValue as IEnumerable <IComposite>;
                // Composite list
                if (compositeList != null && otherCompositeList != null)
                {
                    if (compositeList.Count() != otherCompositeList.Count())
                    {
                        return(false);
                    }
                    for (var i = 0; i < compositeList.Count(); i++)
                    {
                        var item = compositeList.ElementAt(i);
                        if (path.ContainsKey(item))
                        {
                            continue;                         // prevent circular refs
                        }
                        if (!item.EqualsByValueInternal(otherCompositeList.ElementAt(i), path))
                        {
                            return(false);
                        }
                    }
                }
                // Simple property
                if (composite == null && compositeList == null && !Equals(value, otherValue))
                {
                    return(false);
                }
            }
            return(true);
        }