Click or drag to resize
HashCodeBuilder Class
A class used to generate hash codes from object field values inside the GetHashCode method.
Inheritance Hierarchy
SystemObject
  Capgemini.CommonObjectUtilsHashCodeBuilder

Namespace: Capgemini.CommonObjectUtils
Assembly: Capgemini.CommonObjectUtils (in Capgemini.CommonObjectUtils.dll) Version: 1.3.0.0
Syntax
public class HashCodeBuilder

The HashCodeBuilder type exposes the following members.

Constructors
  NameDescription
Public methodHashCodeBuilder
Initializes a new instance of the HashCodeBuilder class.
Public methodHashCodeBuilder(Int32, Int32)
Initializes a new instance of the HashCodeBuilder class.
Top
Methods
  NameDescription
Public methodAppend(Object)
Appends the field to the hash code calculation.
Public methodAppendT(ICollectionT)
Appends the values in a collection field to the hash code calculation.
Public methodAppendBase
Appends the result of the base.GetHashCode method.
Public methodAppendManyT
Appends the values in a collection field to the hash code calculation.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Gets the hash code computed for the fields supplied to this object.
(Overrides ObjectGetHashCode.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks

This class allows you to add field to the hash code calculation in a fluent style.

This is a partial port of the Apache Commons HashCodeBuilder utility class.

Examples
class Foo 
{
    private int field1;
    private int[] field2;

    ...

    public override int GetHashCode()
    {
        return new HashCodeBuilder()
            .Append(field1)
            .AppendMany(field2)
            .GetHashCode();
    }
}
See Also