You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 regels
1.9 KiB

  1. // <copyright file="PrivilegeAndAttributesCollection.cs" company="Nick Lowe">
  2. // Copyright © Nick Lowe 2009
  3. // </copyright>
  4. // <author>Nick Lowe</author>
  5. // <email>nick@int-r.net</email>
  6. // <url>http://processprivileges.codeplex.com/</url>
  7. namespace ProcessPrivileges
  8. {
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Collections.ObjectModel;
  12. using System.Linq;
  13. using System.Text;
  14. /// <summary>Read-only collection of privilege and attributes.</summary>
  15. [Serializable]
  16. public sealed class PrivilegeAndAttributesCollection : ReadOnlyCollection<PrivilegeAndAttributes>
  17. {
  18. internal PrivilegeAndAttributesCollection(IList<PrivilegeAndAttributes> list)
  19. : base(list)
  20. {
  21. }
  22. /// <summary>Returns a <see cref="string"/> representation of the collection.</summary>
  23. /// <returns><see cref="string"/> representation of the collection.</returns>
  24. public override string ToString()
  25. {
  26. StringBuilder stringBuilder = new StringBuilder();
  27. int maxPrivilegeLength = this.Max(privilegeAndAttributes => privilegeAndAttributes.Privilege.ToString().Length);
  28. foreach (PrivilegeAndAttributes privilegeAndAttributes in this)
  29. {
  30. stringBuilder.Append(privilegeAndAttributes.Privilege);
  31. int paddingLength = maxPrivilegeLength - privilegeAndAttributes.Privilege.ToString().Length;
  32. char[] padding = new char[paddingLength];
  33. for (int i = 0; i < paddingLength; i++)
  34. {
  35. padding[i] = ' ';
  36. }
  37. stringBuilder.Append(padding);
  38. stringBuilder.Append(" => ");
  39. stringBuilder.AppendLine(privilegeAndAttributes.PrivilegeAttributes.ToString());
  40. }
  41. return stringBuilder.ToString();
  42. }
  43. }
  44. }