Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

63 Zeilen
1.8 KiB

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