C# Class Tests.CompareObjects

Class that allows comparison of two objects of the same type to each other. Supports classes, lists, arrays, dictionaries, child comparison and more.
Mostrar archivo Open project: AdrianFreemantle/DDD Class Usage Examples

Public Methods

Method Description
ClearCache ( ) : void

Reflection properties and fields are cached. By default this cache is cleared automatically after each compare.

Compare ( object object1, object object2 ) : bool

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

CompareObjects ( ) : System

Set up defaults for the comparison

FindDifferences ( object expected, object actual ) : string

Private Methods

Method Description
AddBreadCrumb ( string existing, string name, string extra, int index ) : string

Add a breadcrumb to an existing breadcrumb

AddBreadCrumb ( string existing, string name, string extra, string index ) : string

Add a breadcrumb to an existing breadcrumb

Compare ( object object1, object object2, string breadCrumb ) : void

Compare two objects

CompareClass ( object object1, object object2, string breadCrumb ) : void

Compare the properties, fields of a class

CompareEnum ( object object1, object object2, string breadCrumb ) : void

Compare an enumeration

CompareIDictionary ( object object1, object object2, string breadCrumb ) : void

Compare a dictionary

CompareIList ( object object1, object object2, string breadCrumb ) : void

Compare an array or something that implements IList

CompareIndexer ( PropertyInfo info, object object1, object object2, string breadCrumb ) : void
ComparePointer ( object object1, object object2, string breadCrumb ) : void

Compare a pointer struct

CompareSimpleType ( object object1, object object2, string breadCrumb ) : void

Compare a simple type

CompareStruct ( object object1, object object2, string breadCrumb ) : void

Compare a struct

CompareTimespan ( object object1, object object2, string breadCrumb ) : void

Compare a timespan struct

GetFieldInfo ( Type type ) : IEnumerable
GetPropertyInfo ( Type type ) : IEnumerable
IgnoredByAttribute ( Type type ) : bool

Check if any type has attributes that should be bypassed

IsArray ( Type t ) : bool
IsChildType ( Type t ) : bool
IsClass ( Type t ) : bool
IsEnum ( Type t ) : bool
IsIDictionary ( Type t ) : bool
IsIList ( Type t ) : bool
IsPointer ( Type t ) : bool
IsSimpleType ( Type t ) : bool
IsStruct ( Type t ) : bool
IsTimespan ( Type t ) : bool
IsValidIndexer ( PropertyInfo info, string breadCrumb ) : bool
PerformCompareFields ( Type t1, object object1, object object2, string breadCrumb ) : void

Compare the fields of a class

PerformCompareProperties ( Type t1, object object1, object object2, string breadCrumb ) : void

Compare the properties of a class

ValidStructSubType ( Type t ) : bool
cStr ( object obj ) : string

Convert an object to a nicely formatted string

Method Details

ClearCache() public method

Reflection properties and fields are cached. By default this cache is cleared automatically after each compare.
public ClearCache ( ) : void
return void

Compare() public method

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
public Compare ( object object1, object object2 ) : bool
object1 object
object2 object
return bool

CompareObjects() public method

Set up defaults for the comparison
public CompareObjects ( ) : System
return System

FindDifferences() public static method

public static FindDifferences ( object expected, object actual ) : string
expected object
actual object
return string