BaseExtensions.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Security.Cryptography;
  7. namespace MediaBrowser.Common.Extensions
  8. {
  9. public static class BaseExtensions
  10. {
  11. static MD5CryptoServiceProvider md5Provider = new MD5CryptoServiceProvider();
  12. public static Guid GetMD5(this string str)
  13. {
  14. lock (md5Provider)
  15. {
  16. return new Guid(md5Provider.ComputeHash(Encoding.Unicode.GetBytes(str)));
  17. }
  18. }
  19. /// <summary>
  20. /// Examine a list of strings assumed to be file paths to see if it contains a parent of
  21. /// the provided path.
  22. /// </summary>
  23. /// <param name="lst"></param>
  24. /// <param name="path"></param>
  25. /// <returns></returns>
  26. public static bool ContainsParentFolder(this List<string> lst, string path)
  27. {
  28. foreach (var str in lst)
  29. {
  30. //this should be a little quicker than examining each actual parent folder...
  31. if (path.Equals(str,StringComparison.OrdinalIgnoreCase)
  32. || (path.StartsWith(str, StringComparison.OrdinalIgnoreCase) && path[str.Length-1] == '\\')) return true;
  33. }
  34. return false;
  35. }
  36. }
  37. }