Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Extensions.cs 1.6 KiB

pirms 8 gadiem
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using Alphaleonis.Win32.Filesystem;
  4. namespace NTFSSecurity
  5. {
  6. public static class Extensions
  7. {
  8. public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
  9. {
  10. if (source == null) { throw new ArgumentException(); }
  11. if (action == null) { throw new ArgumentException(); }
  12. foreach (T element in source)
  13. {
  14. action(element);
  15. }
  16. }
  17. public static FileSystemInfo GetParent(this FileSystemInfo item)
  18. {
  19. var parentPath = System.IO.Path.GetDirectoryName(item.FullName);
  20. if (File.Exists(parentPath))
  21. {
  22. return new FileInfo(parentPath);
  23. }
  24. else if (Directory.Exists(parentPath))
  25. {
  26. return new DirectoryInfo(parentPath);
  27. }
  28. else
  29. {
  30. throw new System.IO.FileNotFoundException();
  31. }
  32. }
  33. public static System.IO.FileSystemInfo GetParent(this System.IO.FileSystemInfo item)
  34. {
  35. var parentPath = System.IO.Path.GetDirectoryName(item.FullName);
  36. if (File.Exists(parentPath))
  37. {
  38. return new System.IO.FileInfo(parentPath);
  39. }
  40. else if (Directory.Exists(parentPath))
  41. {
  42. return new System.IO.DirectoryInfo(parentPath);
  43. }
  44. else
  45. {
  46. throw new System.IO.FileNotFoundException();
  47. }
  48. }
  49. }
  50. }