KellermanSoftware.Compare-NET-Objects
Cache for properties, fields, and methods to speed up reflection
Reflection Cache for property info
Reflection Cache for field info
Reflection Cache for methods
Static constructor
Clear the cache
Get a list of the fields within a type
Get the value of a property
Get a list of the properties in a type
Get a method by name
Get the cached methods for a type
CompareException with a Result Property
CompareException Constructor
The comparison Result
A set of BDD style comparison extensions for use with Testing Frameworks
Alter the configuration for the comparison
Throws a CompareException if the classes are not equal
Throws a CompareException if the classes are equal
Class that allows comparison of two objects of the same type to each other. Supports classes, lists, arrays, dictionaries, child comparison and more.
CompareLogic compareLogic = new CompareLogic();
Person person1 = new Person();
person1.DateCreated = DateTime.Now;
person1.Name = "Greg";
Person person2 = new Person();
person2.Name = "John";
person2.DateCreated = person1.DateCreated;
ComparisonResult result = compareLogic.Compare(person1, person2);
if (!result.AreEqual)
Console.WriteLine(result.DifferencesString);
The default configuration
Set up defaults for the comparison
Pass in the configuration
Compare two objects of the same type to each other.
Check the Differences or DifferencesString Properties for the differences.
Default MaxDifferences is 1 for performance
The expected object value to compare
The actual object value to compare
True if they are equal
Reflection properties and fields are cached. By default this cache is cleared automatically after each compare.
Obsolete Use CompareLogic instead
Obsolete Use CompareLogic instead
Obsolete Use CompareLogic.Config.ShowBreadcrumb instead
Obsolete Use CompareLogic.Config.MembersToIgnore for members or CompareLogic.Config.ClassTypesToIgnore instead
Obsolete Use CompareLogic.Config.MembersToInclude or CompareLogic.Config.ClassTypesToInclude instead
Obsolete Use CompareLogic.Config.CompareStaticProperties instead
Obsolete Use CompareLogic.Config.CompareStaticFields instead
Obsolete Use CompareLogic.Config.CompareChildren instead
Obsolete Use CompareLogic.Config.CompareReadOnly instead
Obsolete Use CompareLogic.Config.CompareFields instead
Obsolete Use CompareLogic.Config.IgnoreCollectionOrder instead
Obsolete Use CompareLogic.Config.CompareProperties instead
Obsolete Use CompareLogic.Config.MaxDifferences instead
Obsolete Use the ComparisonResult.Differences returned from CompareLogic.Compare
Obsolete Use the ComparisonResult.DifferencesString returned from CompareLogic.Compare
Obsolete Use CompareLogic.Config.AutoClearCache instead
Obsolete Use CompareLogic.Config.Caching instead
Obsolete Use CompareLogic.Config.AttributesToIgnore instead
Obsolete Use CompareLogic.Config.IgnoreObjectTypes instead
Obsolete Use CompareLogic.Config.CustomComparers instead
Obsolete Use CompareLogic.Config.CustomComparers instead
Obsolete Use CompareLogic.Config.ExpectedName instead
Obsolete Use CompareLogic.Config.ActualName instead
Obsolete Use CompareLogic.Config.DifferenceCallback instead
Obsolete Use CompareLogic.Config.CollectionMatchingSpec instead
Obsolete Use CompareLogic.Compare instead
Obsolete Use CompareLogic.ClearCache instead
Compare Parameters
The configuration settings
The type of the first object
The type of the second object
Details about the comparison
A reference to the parent object1
A reference to the parent object2
The first object to be compared
The second object to be compared
The breadcrumb in the tree
Custom comparer used to assert Object1
Configuration
Default Constructor
When comparing strings or StringBuilder types, perform a case sensitive comparison. The default is true.
Ignore exceptions when objects are disposed
Ignore millisecond differences between DateTime values or DateTimeOffset values. The default is 0 (any time difference will be shown).
When comparing DateTimeOffsets, offsets will be compared as well as the UtcDateTimes. The default is false.
When comparing DateTimeOffsets, timezone difference will be ignored by changing both object to their UTC equivalent value. The default is false.
When comparing struct, the depth to compare for children. The default is 2, the max is 5
If true, unknown object types will be ignored instead of throwing an exception. The default is false.
If true, invalid indexers will be skipped. The default is false.
If a class implements an interface then only members of the interface will be compared. The default is all members are compared.
Show breadcrumb at each stage of the comparision. The default is false.
This is useful for debugging deep object graphs.
A list of class types to be ignored in the comparison. The default is to compare all class types.
Only these class types will be compared. The default is to compare all class types.
If you specify a class type here no other class types will be compared unless it is in this list.
A list of types to be ignored in the comparison. The default is to compare all types. A typical thing to not compare are GUIDs
Only these types will be compared. The default is to compare all types.
If you specify a type here no others will be compared unless it is in this list. You must specify ALL Types that you want to compare.
Ignore Data Table Names, Data Table Column Names, properties, or fields by name during the comparison. Case sensitive. The default is to compare all members.
MembersToIgnore.Add("CreditCardNumber");
MembersToIgnore.Add("Invoice.InvoiceGuid");
MembersToIgnore.Add("*Id");
Ignore property during the comparison. Property is specific to the generic type.
IgnoreProperty<Person>(x => x.Name)
Only compare elements by name for Data Table Names, Data Table Column Names, properties and fields. Case sensitive. The default is to compare all members.
MembersToInclude.Add("FirstName")
If true, private properties and fields will be compared. The default is false. Silverlight and WinRT restricts access to private variables.
If true, private fields will be compared. The default is false. Silverlight and WinRT restricts access to private variables.
If true, static properties will be compared. The default is true.
If true, static fields will be compared. The default is true.
If true, child objects will be compared. The default is true.
If false, and a list or array is compared list items will be compared but not their children.
If true, compare read only properties (only the getter is implemented). The default is true.
If true, compare fields of a class (see also CompareProperties). The default is true.
If true, compare each item within a collection to every item in the other. The default is false. WARNING: setting this to true significantly impacts performance.
If true, compare properties of a class (see also CompareFields). The default is true.
The maximum number of differences to detect. The default is 1 for performance reasons.
The maximum number of differences to detect when comparing byte arrays. The default is 1.
Reflection properties and fields are cached. By default this cache is cleared after each compare. Set to false to keep the cache for multiple compares.
By default properties and fields for types are cached for each compare. By default this cache is cleared after each compare.
A list of attributes to ignore a class, property or field
AttributesToIgnore.Add(typeof(XmlIgnoreAttribute));
If true, objects will be compared ignore their type diferences. The default is false.
In the differences string, this is the name for expected name. The default is: Expected
In the differences string, this is the name for the actual name. The default is: Actual
Callback invoked each time the comparer finds a difference. The default is no call back.
Sometimes one wants to match items between collections by some key first, and then
compare the matched objects. Without this, the comparer basically says there is no
match in collection B for any given item in collection A that doesn't Compare with a result of true.
The results of this aren't particularly useful for object graphs that are mostly the same, but not quite.
Enter CollectionMatchingSpec
The enumerable strings should be property (not field, for now, to keep it simple) names of the
Type when encountered that will be used for matching
You can use complex type properties, too, as part of the key to match. To match on all props/fields on
such a matching key, Don't set this property (default comparer behavior)
NOTE: types are looked up as exact. e.g. if foo is an entry in the dictionary and bar is a
sub-class of foo, upon encountering a bar type, the comparer will not find the entry of foo
A list of custom comparers that take priority over the built in comparers
A list of custom property comparers that take priority over the built in and type comparers
If true, string.empty and null will be treated as equal for Strings and String Builder. The default is false.
If true, leading and trailing whitespaces will be ignored for Strings and String Builder. The default is false.
The precision to compare double values. The default is 0.
The precision to compare decimal values. The default is 0.
Backing member that supports
Computed value of whether or not exclusion list has wildcards.
Reset the configuration to the default values
Details about the comparison
Keep track of parent objects in the object hierarchy
Set the configuration for the comparison
Keep track of the depth of structs being compared. Used with ComparisonConfig.MaxStructDepth
Configuration
Used to time how long the comparison took
The amount of time in milliseconds it took for the comparison
The differences found during the compare
The differences found in a string suitable for a textbox
Returns true if the objects are equal
Returns true if the number of differences has reached the maximum
Add parent, handle references count
Remove parent, handle references count
Returns true if we have encountered this parent before
Get custom validator based on property
Get validator for a member of an expando object
Get validator for a member
Detailed information about the difference
Name of Expected Object
Name of Actual Object
Returns the parent property name
The breadcrumb of the property leading up to the value
The child property name
Object1 Value as a string
Object2 Value as a string
The type of the first object
The type of the second object
A reference to the parent of object1
A reference to the parent of object2
Object1 as a reference
Object2 as a reference
Prefix to put on the beginning of the message
Item and property name only
The type and index of what is compared
Nicely formatted string
Exclude types depending upon the configuration
Exclude a member of an expando object
Returns true if the property or field should be excluded
Returns true if the property or field should be exluded by wilcard
Check if the class should be exluded by Attribute
Check if the class type should be excluded based on the configuration
Check if any type has attributes that should be bypassed
Helper methods for files and directories
Get the current directory of the executing assembly
Ensure the passed string ends with a directory separator character unless the string is blank.
The string to append the backslash to.
String with a "/" on the end
Config object for HtmlReport
The header value of the Bread Crumb column
The header value of the Expected column
The header value of the Actual column
If true, the output will be complete html, if false, it will just be the table
Setting this will overwrite the default html header (html, head, body tags)
Setting this will overwrite the default html footer (closing body, html tags)
The title of the page - only visible if GenerateFullHtml == true
The CSS Style of the page - only used if the GenerateFullHtml == true
Default constructor, sets default values
Appends to the existing Style value
Any css to append
Replaces the existing Style value
Any css to use
Interface for mocking
The default configuration
Compare two objects of the same type to each other.
Check the Differences or DifferencesString Properties for the differences.
Default MaxDifferences is 1 for performance
The expected object value to compare
The actual object value to compare
True if they are equal
Reflection properties and fields are cached. By default this cache is cleared automatically after each compare.
Logic for comparing lists that are out of order based on a key
Initializes a new instance of the class.
The root comparer.
Compares the enumerators and ignores the order
Implements methods to support the comparison of objects for equality, in a customizable fashion.
Implements methods to support the comparison of objects for equality, in a customizable fashion.
The comparison object type.
Defines the configuration and logic by which Equals comparisons will be performed.
Gets or sets a value indicating whether the base object hashes should be used.
False by default to allow CompareLogic to evaluate equivalence of otherwise instance-sensitive hashing objects.
NOTE: Any object which doesn't override GetHashCode will behave this way, so this property should generally be left false.
Compare two objects of the same type to each other.
True if the objects are considered equivalent, according to the current CompareLogic.
Retrieves the hash of the specified object.
The object to retrieve a hash for.
Helper methods for processes
Execute an external program.
Path and filename of the executable.
Arguments to pass to the executable.
Window style for the process (hidden, minimized, maximized, etc).
Wait for the process to finish.
Exit Code
Generic class for holding a Property Info, or Dynamic Info
Constructor
If true, this is a dynamic property
Name of the property
Value of the property
Let me reflect on this day
The type of the parent
The type of the property
If the property can be read from
If the property can be written to
Indexers for the property
Reference to the property info
Abstract Base Duel File Report that has default Output
Create two difference files and compare in WinMerge
A list of the differences
The path to write the expected results
The path to write the actual results
Launch application to compare two files
The path for the expected file results
The path for the actual file results
Output files and launch Beyond Compare
Launch the WinMerge
The path to write the expected results
The path to write the actual results
Find the path of the Beyond Compare executable
The path or null if not found
Create a CSV file of the differences and launch the default CSV handler (usually Excel)
Output the differences to a file
A list of differences
The file path
Output the differences to a stream
A list of differences
An output stream
Output the differences to a string
A list of differences
A string
Launch the application associated with CSV files
The differences file
Escape special characters
Create an HTML file of the differences and launch the default HTML handler
Default constructor, sets up Config object
HtmlReport Configuration
Output the differences to a file
A list of differences
The file path
Launch the WinMerge
The differences file
Output the differences to a stream
A list of differences
An output stream
Output the differences to a string
A list of differences
A string
Escape special characters
Define a dual file report like Beyond Compare, WinMerge etc.
Output the differences to two files
A list of differences
The path to write the expected results
The path to write the actual results
Launch the comparison application
The path to write the expected results
The path to write the actual results
Defines a Single File Report
Output the differences to a file
A list of differences
The file path
Output the differences to a stream
A list of differences
Where to write to
Output the differences to a string
A list of differences
A string
Launch the application for showing the file
The file path
Report for showing differences to an end user
Initializes a new instance of the class.
The text in between the values. Defaults to: CHANGED TO ->
Output the differences to a file
A list of differences
The file path
Output the differences to a stream
A list of differences
Where to write to
Output the differences to a string
A list of differences
A string
Launch the application for showing the file
The file path
Output files and launch WinMerge
Launch the WinMerge
The path to write the expected results
The path to write the actual results
Find the path of the WinMerge executable
The path or null if not found
The base comparer which contains all the type comparers
A list of the type comparers
Compare two objects
Factory to create a root comparer
Get the current root comparer
Methods for manipulating strings
Insert spaces into a string
OrderDetails = Order Details
10Net30 = 10 Net 30
FTPHost = FTP Host
Common functionality for all Comparers
Add a breadcrumb to an existing breadcrumb
Comparison configuration
The existing breadcrumb
The field or property name
The new breadcrumb
Add a breadcrumb to an existing breadcrumb
The comparison configuration
The existing breadcrumb
The property or field name
Extra information to output after the name
The index for an array, list, or row
The new breadcrumb
Add a breadcrumb to an existing breadcrumb
Comparison configuration
The existing breadcrumb
The field or property name
Extra information to append after the name
The index if it is an array, list, row etc.
The new breadcrumb
Add a difference for the current parameters
Add a difference to the result
The difference to add to the result
The comparison result
Convert an object to a nicely formatted string
Common functionality for all Type Comparers
A reference to the root comparer as newed up by the RootComparerFactory
Protected constructor that references the root comparer
If true the type comparer will handle the comparison for the type
The type of the first object
The type of the second object
Compare the two objects
Compare two byte arrays
Protected constructor that references the root comparer
The root comparer.
If true the type comparer will handle the comparison for the type
The type of the first object
The type of the second object
true if it is a byte array; otherwise, false.
Compare two byte array objects
Compare two objects of type class
Constructor for the class comparer
The root comparer instantiated by the RootComparerFactory
Returns true if the both objects are a class
The type of the first object
The type of the second object
Compare two classes
Logic to compare two collections of different types.
The main constructor.
Returns true if both objects are collections.
The type of the first object
The type of the second object
Compare two collections.
Compare two generic objects
The type of the first object
The type of the second object
Method to evaluate the results, return true if two objects are equal
Constructor that takes a root comparer
Constructor that takes a default root comparer
Constructor that takes a the predication with a default root comparer
A function to determine if two objects are equal
Constructor that takes a the predication with a root comparer
The root comparer
Method to determine if two objects are equal
Compare two objects
Returns true if both objects match their types
The type of the first object
The type of the second object
Compare dates with the option to ignore based on milliseconds
Constructor that takes a root comparer
Returns true if both types are DateTime
Compare two DateTime variables
Compare DateTimeOffsets with the ability to ignore millisecond differences
Constructor that takes a root comparer
Returns true if both types are DateTimeOffset
Compare two DateTimeOffset
Compare Decimal values with the ability to specify the precision
Constructor that takes a root comparer
Returns true if both types are double
Compare two decimals
Logic to compare two dictionaries
Constructor that takes a root comparer
Returns true if both types are dictionaries
The type of the first object
The type of the second object
Compare two dictionaries
Compare Double values with the ability to specify the precision
Constructor that takes a root comparer
Returns true if both types are double
Compare two doubles
Logic to compare to enum values
Constructor with a default root comparer
Returns true if both objects are of type enum
The type of the first object
The type of the second object
Compare two enums
Logic to compare two LINQ enumerators
Constructor that takes a root comparer
Returns true if either object is of type LINQ Enumerator
The type of the first object
The type of the second object
Compare two objects that implement LINQ Enumerator
Compare all the fields of a class or struct (Note this derrives from BaseComparer, not TypeComparer)
Constructor with a root comparer
Compare the fields of a class
Logic to compare two hash sets
Constructor that takes a root comparer
Returns true if both objects are hash sets
The type of the first object
The type of the second object
Compare two hash sets
Compares System.Collections.Immutable.ImmutableArray
Constructor that takes a root comparer
Returns true if both are immutable arrays with same generic argument type
The type of the first object
The type of the second object
Compares two immutable arrays
Logic to compare an integer indexer (Note, inherits from BaseComparer, not TypeComparer)
Constructor that takes a root comparer
Compare an integer indexer
Compare objects that implement IList
Constructor that takes a root comparer
Returns true if both objects implement IList
The type of the first object
The type of the second object
Compare two objects that implement IList
Logic to compare to pointers
Constructor that takes a root comparer
Returns true if both types are a pointer
The type of the first object
The type of the second object
Compare two pointers
Compare two properties (Note inherits from BaseComparer instead of TypeComparer
Constructor that takes a root comparer
Compare the properties of a class
Compare a single property of a class
Logic to compare two runtime types
Constructor that takes a root comparer
Returns true if both types are of type runtme type
Compare two runtime types
Compare primitive types (long, int, short, byte etc.) and DateTime, decimal, and Guid
Constructor that takes a root comparer
Returns true if the type is a simple type
The type of the first object
The type of the second object
Compare two simple types
Compare two StringBuilders
Constructor that takes a root comparer
Returns true if both objects are a StringBuilder
The type of the first object
The type of the second object
Compare two string builders
Compare two strings
Constructor that takes a root comparer
Returns true if both objects are a string or if one is a string and one is a a null
The type of the first object
The type of the second object
Compare two strings
Compare two structs
Constructor that takes a root comparer
Returns true if both objects are of type struct
Compare two structs
Logic to compare two timespans
Constructor that takes a root comparer
Returns true if both objects are timespans
The type of the first object
The type of the second object
Compare two timespans
Compare two URIs
Constructor that takes a root comparer
Returns true if both types are a URI
The type of the first object
The type of the second object
Compare two URIs
Methods for detecting
Returns true if it is a dynamic object
Determines whether the specified object is an expando object
The object value.
Returns true if it is a byte array
Returns true if the type can have children
True if the type is an array
True if the type is an System.Collections.Immutable.ImmutableArray
Returns true if it is a struct
Returns true if the type is a timespan
Return true if the type is a class
Return true if the type is an interface
Return true if the type is a URI
Return true if the type is a pointer
Return true if the type is an enum
Return true if the type is a dictionary
Return true if the type is a hashset
Return true if the type is a List
Return true if the type is an Enumerable
Return true if the type is a Double
Return true if the type is a Decimal
Return true if the type is a Decimal or Nullable Decimal
Return true if the type is a DateTime
Return true if the type is a DateTimeOffset
Return true if the type is a StringBuilder
Return true if the type is a string
Return true if the type is a primitive type, date, decimal, string, or GUID
Returns true if the Type is a Runtime type
Used internally to verify the config settings before comparing
Verifies the specified configuration.
The configuration.
Verifies the collection matching spec.
The configuration.
HTML-encodes a string and returns the encoded string.
The text string to encode.
The HTML-encoded text.