using System; using System.IO; using System.IO.Abstractions; using System.Security.Cryptography; namespace Quadarax.Foundation.Core.IO.Extensions { public static class FileInfoExt { public static string GetCalculatedHash(this IFileInfo fileInfo, HashAlgorithm algorithm) { if (fileInfo == null) throw new ArgumentNullException(nameof(fileInfo)); if (algorithm==null) throw new ArgumentNullException(nameof(algorithm)); using (var stream = fileInfo.Open(FileMode.Open,FileAccess.Read, FileShare.ReadWrite)) { return stream.GetStreamCalculatedHash(algorithm); } } } }