FileInfoExt.cs 753 B

12345678910111213141516171819202122232425
  1. using System;
  2. using System.IO;
  3. using System.IO.Abstractions;
  4. using System.Security.Cryptography;
  5. namespace Quadarax.Foundation.Core.IO.Extensions
  6. {
  7. public static class FileInfoExt
  8. {
  9. public static string GetCalculatedHash(this IFileInfo fileInfo, HashAlgorithm algorithm)
  10. {
  11. if (fileInfo == null)
  12. throw new ArgumentNullException(nameof(fileInfo));
  13. if (algorithm==null)
  14. throw new ArgumentNullException(nameof(algorithm));
  15. using (var stream = fileInfo.Open(FileMode.Open,FileAccess.Read, FileShare.ReadWrite))
  16. {
  17. return stream.GetStreamCalculatedHash(algorithm);
  18. }
  19. }
  20. }
  21. }