Interface IStructuralSecureEqualityComparer<T>
- Namespace
- Nerdbank.MessagePack
- Assembly
- Nerdbank.MessagePack.dll
An interface that may be implemented by user-defined types in order to provide their own deep (i.e. giving all values a chance to contribute) hash code.
public interface IStructuralSecureEqualityComparer<T>
Type Parameters
T
The same type that is implementing this interface.
Remarks
When a type implements this interface, GetHashCode() and StructuralEquals(T?) is used to determine equality and hash codes for the type by the StructuralEqualityComparer equality comparer instead of the deep by-value automatic implementation.
Methods
GetHashCode()
Gets a hash code for this object, which may not be collision resistant.
int GetHashCode()
Returns
- int
A 32-bit integer.
Remarks
This method should be compatible with StructuralEquals(T?) such that if two objects are structurally equal, they will return the same hash code. On types that implement Equals(object) with shallow equality, this means this GetHashCode() method may need to be implemented as an explicit interface implementation so it can have structural equality semantics while GetHashCode() can match the default shallow equality semantics.
On .NET, the default implementation of this method is to truncate the result of GetSecureHashCode().
GetSecureHashCode()
Gets a collision resistant hash code for this object.
long GetSecureHashCode()
Returns
- long
A 64-bit integer.
Remarks
This method should be compatible with StructuralEquals(T?) such that if two objects are structurally equal, they will return the same hash code.
Exceptions
- NotSupportedException
May be thrown if not supported.
StructuralEquals(T?)
Tests deep equality of this object with another object.
bool StructuralEquals(T? other)
Parameters
other
TThe other object.
Returns
Remarks
An implementation may use GetDefault<T>(ITypeShape<T>) to obtain equality comparers for any sub-values that must be tested.