25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PrivilegeAndAttributes.cs 3.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // <copyright file="PrivilegeAndAttributes.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. /// <summary>Structure that links <see cref="Privilege"/> and <see cref="PrivilegeAttributes"/> together.</summary>
  11. public struct PrivilegeAndAttributes : IEquatable<PrivilegeAndAttributes>
  12. {
  13. private readonly Privilege privilege;
  14. private readonly PrivilegeAttributes privilegeAttributes;
  15. internal PrivilegeAndAttributes(Privilege privilege, PrivilegeAttributes privilegeAttributes)
  16. {
  17. this.privilege = privilege;
  18. this.privilegeAttributes = privilegeAttributes;
  19. }
  20. /// <summary>Gets the privilege.</summary>
  21. /// <value>The privilege.</value>
  22. public Privilege Privilege
  23. {
  24. get
  25. {
  26. return this.privilege;
  27. }
  28. }
  29. /// <summary>Gets the privilege attributes.</summary>
  30. /// <value>The privilege attributes.</value>
  31. public PrivilegeAttributes PrivilegeAttributes
  32. {
  33. get
  34. {
  35. return this.privilegeAttributes;
  36. }
  37. }
  38. /// <summary>Gets the privilege state.</summary>
  39. /// <value>The privilege state.</value>
  40. /// <remarks>Derived from <see cref="PrivilegeAttributes"/>.</remarks>
  41. public PrivilegeState PrivilegeState
  42. {
  43. get
  44. {
  45. return ProcessExtensions.GetPrivilegeState(this.privilegeAttributes);
  46. }
  47. }
  48. /// <summary>Compares two instances for equality.</summary>
  49. /// <param name="first">First instance.</param>
  50. /// <param name="second">Second instance.</param>
  51. /// <returns>Value indicating equality of instances.</returns>
  52. public static bool operator ==(PrivilegeAndAttributes first, PrivilegeAndAttributes second)
  53. {
  54. return first.Equals(second);
  55. }
  56. /// <summary>Compares two instances for inequality.</summary>
  57. /// <param name="first">First instance.</param>
  58. /// <param name="second">Second instance.</param>
  59. /// <returns>Value indicating inequality of instances.</returns>
  60. public static bool operator !=(PrivilegeAndAttributes first, PrivilegeAndAttributes second)
  61. {
  62. return !first.Equals(second);
  63. }
  64. /// <summary>Returns the hash code for this instance.</summary>
  65. /// <returns>The hash code for this instance.</returns>
  66. public override int GetHashCode()
  67. {
  68. return this.privilege.GetHashCode() ^ this.privilegeAttributes.GetHashCode();
  69. }
  70. /// <summary>Indicates whether this instance and a specified object are equal.</summary>
  71. /// <param name="obj">Another object to compare to.</param>
  72. /// <returns>Value indicating whether this instance and a specified object are equal.</returns>
  73. public override bool Equals(object obj)
  74. {
  75. return obj is PrivilegeAttributes ? this.Equals((PrivilegeAttributes)obj) : false;
  76. }
  77. /// <summary>Indicates whether this instance and another instance are equal.</summary>
  78. /// <param name="other">Another instance to compare to.</param>
  79. /// <returns>Value indicating whether this instance and another instance are equal.</returns>
  80. public bool Equals(PrivilegeAndAttributes other)
  81. {
  82. return this.privilege == other.Privilege && this.privilegeAttributes == other.PrivilegeAttributes;
  83. }
  84. public override string ToString()
  85. {
  86. return privilege.ToString();
  87. }
  88. }
  89. }