Joutsen v0.5.0+12-g5dd5f7e
Public Member Functions | Protected Member Functions | Properties | List of all members
Joutsen.Reflection.PropertiesEqualityComparer Class Reference

An implementation of System.Collections.Generic.IEqualityComparer that uses reflection to check the public properties for equality. More...

Public Member Functions

 PropertiesEqualityComparer (params string[] ignoredProperties)
 Creates a new instance of Framework.System.Reflection.PropertiesEqualityComparer which will compare elements of System.Collections.IEnumerables also by their public properties. More...
 
 PropertiesEqualityComparer (SCG.IEqualityComparer< object > elementsComparer, params string[] ignoredProperties)
 Creates a new instance of Framework.System.Reflection.PropertiesEqualityComparer which will use the elementsComparer to compare the elements of System.Collections.IEnumerables. More...
 
new bool Equals (object x, object y)
 Determines whether the specified objects are equal by checking the public properties for equality. More...
 
int GetHashCode (object obj)
 Returns a hash code for the specified object. More...
 
Set< string > GetDifferingProperties (object x, object y)
 Fetches a set of names of properties which are not equal. More...
 
bool SameInstance (object x, object y)
 

Protected Member Functions

bool IsEnumerable (PropertyInfo info)
 Checks if info describes an enumerable property. More...
 
bool AreElementsEqual (IEnumerable expected, IEnumerable actual)
 Checks the elements of two instances of System.Collections.IEnumerable for equality. More...
 

Properties

Set< string > IgnoredProperties [get]
 The names of the properties that are not compared when checking for equality. More...
 

Detailed Description

An implementation of System.Collections.Generic.IEqualityComparer that uses reflection to check the public properties for equality.

Remarks
The current implementation does not compare indexer properties.
Since
0.2.0

Constructor & Destructor Documentation

◆ PropertiesEqualityComparer() [1/2]

Joutsen.Reflection.PropertiesEqualityComparer.PropertiesEqualityComparer ( params string[]  ignoredProperties)

Creates a new instance of Framework.System.Reflection.PropertiesEqualityComparer which will compare elements of System.Collections.IEnumerables also by their public properties.

Parameters
ignoredPropertiesthe names of the properties that are not taken into account when checking for equality

◆ PropertiesEqualityComparer() [2/2]

Joutsen.Reflection.PropertiesEqualityComparer.PropertiesEqualityComparer ( SCG.IEqualityComparer< object >  elementsComparer,
params string[]  ignoredProperties 
)

Creates a new instance of Framework.System.Reflection.PropertiesEqualityComparer which will use the elementsComparer to compare the elements of System.Collections.IEnumerables.

Parameters
elementsComparerthe Framework.System.Reflection.PropertiesEqualityComparer that will be used to check if elements of properties of type System.Collections.IEnumerable are equal
ignoredPropertiesthe names of the properties that are not taken into account when checking for equality

Member Function Documentation

◆ AreElementsEqual()

bool Joutsen.Reflection.PropertiesEqualityComparer.AreElementsEqual ( IEnumerable  expected,
IEnumerable  actual 
)
protected

Checks the elements of two instances of System.Collections.IEnumerable for equality.

Parameters
expectedThe first instance of System.Collections.IEnumerable.
actualThe second instance of System.Collections.IEnumerable.
Returns
true if he elements of both instances are equal, otherwise false.

◆ Equals()

new bool Joutsen.Reflection.PropertiesEqualityComparer.Equals ( object  x,
object  y 
)

Determines whether the specified objects are equal by checking the public properties for equality.

Parameters
xthe first object to compare
ythe second object to compare
Returns
true if the specified objects are equal, otherwise false
Remarks
If both objects are null they are considered equal.

◆ GetDifferingProperties()

Set< string > Joutsen.Reflection.PropertiesEqualityComparer.GetDifferingProperties ( object  x,
object  y 
)

Fetches a set of names of properties which are not equal.

Parameters
xthe first object to compare
ythe second object to compare
Returns
a set of names of properties whose values are not equal
Exceptions
System.ArgumentNullExceptionif either x or y are null

◆ GetHashCode()

int Joutsen.Reflection.PropertiesEqualityComparer.GetHashCode ( object  obj)

Returns a hash code for the specified object.

Parameters
objthe Object for which a hash code is to be returned.
Returns
a hash code for the specified object
Exceptions
System.ArgumentNullExceptionif obj is null
Remarks
This method simply sums up the hashcodes of the property values. This is not an efficient hashcode calculation but should only be used for testing or if no hashcode implementation is available.

◆ IsEnumerable()

bool Joutsen.Reflection.PropertiesEqualityComparer.IsEnumerable ( PropertyInfo  info)
protected

Checks if info describes an enumerable property.

Parameters
infothe property info to check
Returns
true if info describes an enumerable property, otherwise false

◆ SameInstance()

bool Joutsen.Reflection.PropertiesEqualityComparer.SameInstance ( object  x,
object  y 
)

Property Documentation

◆ IgnoredProperties

Set<string> Joutsen.Reflection.PropertiesEqualityComparer.IgnoredProperties
get

The names of the properties that are not compared when checking for equality.