예제 #1
0
        public void HashData(object data)
        {
            if (!_byteExtractor.CanExtract(data.GetType()))
            {
                throw new InvalidOperationException("Cannot hash " + data.GetType());
            }

            _byteExtractor.Extract(data, _stream);
        }
예제 #2
0
        /// <inheritdoc />
        public IHash Factory(object input)
        {
            if (!_byteExtractor.CanExtract(input.GetType()))
            {
                throw new ArgumentException(CannotHashMessage(input));
            }

            using (var stream = new MemoryStream())
                using (var safeStream = Stream.Synchronized(stream))
                {
                    _byteExtractor.Extract(input, safeStream);
                    safeStream.Position = 0;
                    return(new StreamHash(safeStream, _algorithmGenerator.Invoke()));
                }
        }
예제 #3
0
 private bool CanExtractEnumerable(Type t) =>
 typeof(IEnumerable).IsAssignableFrom(t) &&
 _elementExtractor.CanExtract(t.GenericTypeArguments.Single());