/// <summary>
        /// Recursively loops through the customization object hierarchy and creates a CustomizationComparison hierarchy.
        /// </summary>
        /// <param name="parent">The parent CustomizationComparison.</param>
        /// <param name="prop">The property that source and target are values of.</param>
        /// <param name="source">The source value.</param>
        /// <param name="target">The target value.</param>
        private void BuildComparisons(CustomizationComparison parent, PropertyInfo prop, object source, object target)
        {
            // Make sure at least one value is not null
            if (source != null || target != null)
            {
                // Extract the value types
                Type type = GetCommonType(source, target);

                // Don't continue if the types differ
                if (type == null)
                {
                    parent.IsDifferent = true;
                }
                else
                {
                    CustomizationComparison originalParent = parent;

                    // Determine if a new CustomizationComparison node should be created
                    if (type != typeof(ImportExportXml) && ComparisonTypeMap.IsTypeComparisonType(type))
                    {
                        string name = ComparisonTypeMap.GetComparisonTypeName(source, target);

                        parent = new CustomizationComparison(name, source, target);
                        parent.ParentProperty = prop;
                        originalParent.Children.Add(parent);
                    }

                    if (IsSimpleType(type))
                    {
                        // for simple types just compare values
                        if (!Object.Equals(source, target))
                        {
                            originalParent.IsDifferent = true;
                            parent.IsDifferent         = true;
                        }
                    }
                    else if (typeof(IEnumerable).IsAssignableFrom(type))
                    {
                        // Several arrays need to be sorted by a specific property (for example: Entity name)
                        originalParent.IsDifferent |= BuildArrayComparisonTypes(parent, prop, (IEnumerable)source, (IEnumerable)target);
                    }
                    else
                    {
                        // for classes, just compare each property
                        foreach (PropertyInfo p in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                        {
                            if (p.CanRead)
                            {
                                object sourceValue = source != null?p.GetValue(source, null) : null;

                                object targetValue = target != null?p.GetValue(target, null) : null;

                                BuildComparisons(parent, p, sourceValue, targetValue);
                                originalParent.IsDifferent |= parent.IsDifferent;
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        private string GetTypeName(CustomizationComparison self, string typeString)
        {
            object selfValue = self.SourceValue ?? self.TargetValue;

            if (selfValue is IIdentifiable[])
            {
                typeString = ComparisonTypeMap.GetComparisonTypeName(selfValue);
            }

            return(typeString);
        }