Grant.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) Alibaba Cloud Computing
  3. * All rights reserved.
  4. *
  5. * 版权所有 (C)阿里云计算有限公司
  6. */
  7. using System;
  8. namespace Aliyun.OSS
  9. {
  10. /// <summary>
  11. /// 访问控制的授权信息。
  12. /// </summary>
  13. public class Grant {
  14. /// <summary>
  15. /// 获取被授权者信息。
  16. /// </summary>
  17. public IGrantee Grantee { get; private set; }
  18. /// <summary>
  19. /// 获取被授权的权限。
  20. /// </summary>
  21. public Permission Permission { get; private set; }
  22. /// <summary>
  23. /// 构造一个新的<see cref="Grant" />实体。
  24. /// </summary>
  25. /// <param name="grantee">被授权者。目前只支持<see cref="GroupGrantee.AllUsers" />。</param>
  26. /// <param name="permission">权限。</param>
  27. public Grant(IGrantee grantee, Permission permission)
  28. {
  29. if (grantee == null)
  30. throw new ArgumentNullException("grantee");
  31. Grantee = grantee;
  32. Permission = permission;
  33. }
  34. /// <summary>
  35. /// 判断两个<see cref="Grant" />是否相等
  36. /// </summary>
  37. /// <param name="obj">需要比较的<see cref="Grant" /></param>
  38. /// <returns></returns>
  39. public override bool Equals(Object obj)
  40. {
  41. var g = obj as Grant;
  42. if (g == null)
  43. return false;
  44. return Grantee.Identifier== g.Grantee.Identifier &&
  45. Permission == g.Permission;
  46. }
  47. /// <summary>
  48. /// 获取HashCode值
  49. /// </summary>
  50. /// <returns>hash code值</returns>
  51. public override int GetHashCode()
  52. {
  53. return (Grantee.Identifier + ":" + Permission).GetHashCode();
  54. }
  55. }
  56. }