Esempio n. 1
0
        private static void HandleRecursiveComparison(BindingFlags propertyBindingFlags, List <string> validationErrorsList, bool ignoreComplexTypes, string sourceObjectName, PropertyInfo propertyInfo,
                                                      Type sourceType,
                                                      ref bool allMatched, object sourceVal, object targetVal)
        {
            if (sourceVal != null || targetVal != null)
            {
                if (sourceVal != null)
                {
                    if (targetVal == null)
                    {
                        // ReSharper disable once ExpressionIsAlwaysNull - this is for proper error handling (using consistent method for all comparisons)
                        ObjectComparison.CompareValues(sourceVal, targetVal, propertyInfo, sourceType, ref allMatched, validationErrorsList, sourceObjectName);
                    }
                    else
                    {
                        bool innerMatched = sourceVal.PropertiesAreEqual(targetVal, propertyBindingFlags,
                                                                         throwIfNotEqual: false,
                                                                         validationErrorsList: validationErrorsList,
                                                                         ignoreComplexTypes: ignoreComplexTypes,
                                                                         recursiveValidation: true,
                                                                         sourceObjectName: propertyInfo.Name);
                        if (!innerMatched)
                        {
                            allMatched = false;
                        }
                    }
                }
            }

            else
            {
                // ReSharper disable once ExpressionIsAlwaysNull - this is for proper error handling (using consistent method for all comparisons)
                ObjectComparison.CompareValues(sourceVal, targetVal, propertyInfo, sourceType, ref allMatched, validationErrorsList, sourceObjectName);
            }
        }
Esempio n. 2
0
        private static void CompareProperties <T>(T source, T target, BindingFlags propertyBindingFlags, bool recursiveValidation, bool ignoreComplexTypes, List <string> validationErrorsList, string sourceObjectName,
                                                  PropertyInfo propertyInfo, Type sourceType, ref bool allMatched) where T : class
        {
            if (propertyInfo.IsNonStringEnumerable())
            {
                ObjectComparison.HandleListComparison(source, target, propertyBindingFlags, validationErrorsList, ignoreComplexTypes, propertyInfo, sourceType, ref allMatched);
            }
            else
            {
                object sourceVal = propertyInfo.GetValue(source, null);
                object targetVal = propertyInfo.GetValue(target, null);

                if (propertyInfo.GetUnderlyingType().IsSimpleType())
                {
                    ObjectComparison.CompareValues(sourceVal, targetVal, propertyInfo, sourceType, ref allMatched, validationErrorsList, sourceObjectName);
                }
                else
                {
                    if (ignoreComplexTypes)
                    {
                        return;
                    }
                    if (!recursiveValidation)
                    {
                        ObjectComparison.CompareValues(sourceVal, targetVal, propertyInfo, sourceType, ref allMatched, validationErrorsList, sourceObjectName);
                    }
                    else
                    {
                        ObjectComparison.HandleRecursiveComparison(propertyBindingFlags, validationErrorsList, false, sourceObjectName, propertyInfo, sourceType, ref allMatched, sourceVal,
                                                                   targetVal);
                    }
                }
            }
        }