From 61d0597f64d584f77f2ecd54bdbe15b7e6ced411 Mon Sep 17 00:00:00 2001 From: Mohammad Date: Tue, 23 Jan 2018 23:12:32 +0300 Subject: [PATCH] Added GetHashCode() implementation to ValueObject This will be very helpful to readers. Picked it up from eShopOnContainers repo. --- .../implement-value-objects.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/standard/microservices-architecture/microservice-ddd-cqrs-patterns/implement-value-objects.md b/docs/standard/microservices-architecture/microservice-ddd-cqrs-patterns/implement-value-objects.md index ff051ed017651..7c2f7beb3ea1f 100644 --- a/docs/standard/microservices-architecture/microservice-ddd-cqrs-patterns/implement-value-objects.md +++ b/docs/standard/microservices-architecture/microservice-ddd-cqrs-patterns/implement-value-objects.md @@ -87,6 +87,13 @@ public abstract class ValueObject } return !thisValues.MoveNext() && !otherValues.MoveNext(); } + + public override int GetHashCode() + { + return GetAtomicValues() + .Select(x => x != null ? x.GetHashCode() : 0) + .Aggregate((x, y) => x ^ y); + } // Other utilility methods } ```