Details about the comparison
コード例 #1
0
 private static string BuildExpectedNotEqualMessage(string message, ComparisonResult result)
 {
     message = message ?? "Objects expected NOT to be equal";
     return(message + Environment.NewLine + result.DifferencesString + Environment.NewLine);
 }
コード例 #2
0
ファイル: Cache.cs プロジェクト: vishal-h/Compare-Net-Objects
 /// <summary>
 /// Get the value of a property
 /// </summary>
 /// <param name="result"> </param>
 /// <param name="type"></param>
 /// <param name="objectValue"></param>
 /// <param name="propertyName"></param>
 /// <returns></returns>
 public static object GetPropertyValue(ComparisonResult result, Type type, object objectValue, string propertyName)
 {
     lock (_propertyCache)
         return(GetPropertyInfo(result, type).First(o => o.Name == propertyName).GetValue(objectValue, null));
 }
コード例 #3
0
ファイル: CompareObjects.cs プロジェクト: andyfengc/Demo_.Net
        public bool Compare(object object1, object object2)
        {
            _result = _logic.Compare(object1, object2);

            return _result.AreEqual;
        }
コード例 #4
0
ファイル: CompareObjects.cs プロジェクト: andyfengc/Demo_.Net
 public CompareObjects(bool useAppConfigSettings)
 {
     _logic = new CompareLogic(useAppConfigSettings);
     _result = new ComparisonResult(_logic.Config);
 }
コード例 #5
0
 public CompareObjects(bool useAppConfigSettings)
 {
     _logic  = new CompareLogic(useAppConfigSettings);
     _result = new ComparisonResult(_logic.Config);
 }
コード例 #6
0
ファイル: CompareObjects.cs プロジェクト: andyfengc/Demo_.Net
 public CompareObjects()
 {
     _logic = new CompareLogic();
     _result = new ComparisonResult(_logic.Config);
 }
コード例 #7
0
 public CompareObjects()
 {
     _logic  = new CompareLogic();
     _result = new ComparisonResult(_logic.Config);
 }
コード例 #8
0
        public bool Compare(object object1, object object2)
        {
            _result = _logic.Compare(object1, object2);

            return(_result.AreEqual);
        }
コード例 #9
0
 /// <summary>
 /// CompareException Constructor
 /// </summary>
 /// <param name="result"></param>
 /// <param name="message"></param>
 public CompareException(ComparisonResult result, string message) : base(message)
 {
     Result = result;
 }
コード例 #10
0
ファイル: Cache.cs プロジェクト: andyfengc/Demo_.Net
        /// <summary>
        /// Get a list of the properties in a type
        /// </summary>
        /// <param name="result"> </param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static IEnumerable<PropertyInfo> GetPropertyInfo(ComparisonResult result, Type type)
        {
            lock (_propertyCache)
            {
                if (result.Config.Caching && _propertyCache.ContainsKey(type))
                    return _propertyCache[type];

                PropertyInfo[] currentProperties;

#if PORTABLE
            if (!result.Config.CompareStaticProperties)
                currentProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            else
                currentProperties = type.GetProperties(); //Default is public instance and static
#else
                if (result.Config.ComparePrivateProperties && !result.Config.CompareStaticProperties)
                    currentProperties =
                        type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                else if (result.Config.ComparePrivateProperties && result.Config.CompareStaticProperties)
                    currentProperties =
                        type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic |
                                           BindingFlags.Static);
                else if (!result.Config.CompareStaticProperties)
                    currentProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                else
                    currentProperties = type.GetProperties(); //Default is public instance and static
#endif

                if (result.Config.Caching)
                    _propertyCache.Add(type, currentProperties);

                return currentProperties;
            }
        }
コード例 #11
0
ファイル: Cache.cs プロジェクト: andyfengc/Demo_.Net
 /// <summary>
 /// Get the value of a property
 /// </summary>
 /// <param name="result"> </param>
 /// <param name="type"></param>
 /// <param name="objectValue"></param>
 /// <param name="propertyName"></param>
 /// <returns></returns>
 public static object GetPropertyValue(ComparisonResult result, Type type, object objectValue, string propertyName)
 {
     lock (_propertyCache)
         return GetPropertyInfo(result, type).First(o => o.Name == propertyName).GetValue(objectValue, null);
 }
コード例 #12
0
ファイル: CompareLogic.cs プロジェクト: andyfengc/Demo_.Net
        /// <summary>
        /// Compare two objects of the same type to each other.
        /// </summary>
        /// <remarks>
        /// Check the Differences or DifferencesString Properties for the differences.
        /// Default MaxDifferences is 1 for performance
        /// </remarks>
        /// <param name="object1"></param>
        /// <param name="object2"></param>
        /// <returns>True if they are equal</returns>
        public ComparisonResult Compare(object object1, object object2)
        {
            ComparisonResult result = new ComparisonResult(Config);

            #if !PORTABLE
                result.Watch.Start();
            #endif

            RootComparer rootComparer = RootComparerFactory.GetRootComparer();

            CompareParms parms = new CompareParms
            {
                Config = Config,
                Result = result,
                Object1 = object1,
                Object2 = object2,
                BreadCrumb = string.Empty
            };

            rootComparer.Compare(parms);

            if (Config.AutoClearCache)
                ClearCache();

            #if !PORTABLE
                result.Watch.Stop();
            #endif

            return result;
        }
コード例 #13
0
ファイル: Deeply.cs プロジェクト: rslijp/sharptiles
            public override bool Matches(object actualValue)
            {
                actual = actualValue;

                _comparisonResult = new CompareLogic(_comparisonConfig).Compare(actualValue, _expectedValue);

                return _comparisonResult.AreEqual;
            }