A class that represents a given composite type.
Наследование: SimplType
Пример #1
0
        /// <summary>
        /// Performs a value equality check on the values in LHS and RHS described by this field. 
        /// </summary>
        /// <param name="leftContext">Left context object</param>
        /// <param name="rightContext">Right context object</param>
        /// <returns>True if the values described by each context are the same</returns>
        public bool ContextSimplEquals(object leftContext, object rightContext)
        {
            var leftSideDescribedValue = this.GetValue(leftContext);
            var rightSideDescribedValue = this.GetValue(rightContext);

            if(leftSideDescribedValue.GetType().Equals(rightSideDescribedValue.GetType()))
            {
                if(this.IsComposite)
                {
                    var compositetype = new CompositeType(leftSideDescribedValue.GetType());
                    return compositetype.SimplEquals(leftSideDescribedValue, rightSideDescribedValue);
                }
                else if (this.IsCollection)
                {
                    return CollectionType.SimplEquals(leftSideDescribedValue, rightSideDescribedValue);
                }
                else if (this.IsScalar)
                {
                    return this.ScalarType.SimplEquals(leftSideDescribedValue, rightSideDescribedValue);
                }
                else
                {
                    throw new Exception("Unexpected type found at ContextSimplEquals!");
                }
            }
            else
            {
                return false;
            }
        }
Пример #2
0
        private bool RecursiveSimplEquals(object left, object right, List<object> leftCompared, List<object> rightCompared)
        {
            leftCompared.Add(left);
            rightCompared.Add(right);

            if (left.GetType().Equals(right.GetType()))
            {
                foreach (var fieldDescriptor in this.Type.AllFieldDescriptors)
                {
                    var leftDescribedValue = fieldDescriptor.GetValue(left);
                    var rightDescribedValue = fieldDescriptor.GetValue(right);

                    if (fieldDescriptor.IsComposite)
                    {

                        if (object.ReferenceEquals(leftDescribedValue, left) || Object.ReferenceEquals(rightDescribedValue,right))
                        {
                            // Circular refernces are fine, skip them / move on.
                            continue;
                        }

                        if (leftCompared.Contains(leftDescribedValue) || rightCompared.Contains(rightDescribedValue))
                        {
                            // Skip cycles.
                            continue;
                        }

                        var composite = new CompositeType(leftDescribedValue.GetType());
                        return composite.SimplEquals(leftDescribedValue, rightDescribedValue, leftCompared, rightCompared);
                    }
                    else
                    {
                        if (!fieldDescriptor.ContextSimplEquals(left,right))
                        {
                            return false;
                        }
                    }
                }

                return true;
            }
            else
            {
                return false;
            }
        }