Ejemplo n.º 1
0
        public ComputeFingerprintCallback <T> Build([NotNull] ComputeHashCallback computeHashCallback)
        {
            if (computeHashCallback == null)
            {
                throw new ArgumentNullException(nameof(computeHashCallback));
            }

            FingerprintBuilderValidator.Validate(this).Assert();

            var binaryFormatter = new BinaryFormatter();

            return(obj =>
            {
                using (var memory = new MemoryStream())
                {
                    foreach (var item in _valueSelectors)
                    {
                        var value = item.Value(obj);
                        if (!(value is null))
                        {
                            binaryFormatter.Serialize(memory, value);
                        }
                    }
                    return computeHashCallback(memory.ToArray());
                }
            });
        }
Ejemplo n.º 2
0
 public static ExpressValidationResultLookup <T> ValidateWith <T>([NotNull] this T value, [NotNull] IExpressValidator <T> vaccine) => vaccine.Validate(value);