PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/V1/trunk/Source/CAL/Composite/Events/SubscriptionToken.cs

#
C# | 76 lines | 26 code | 6 blank | 44 comment | 3 complexity | dcd3bcb8ff141df9dd718782fac88a8f MD5 | raw file
  1. //===============================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation
  4. //===============================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===============================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===============================================================================
  17. using System;
  18. namespace Microsoft.Practices.Composite.Events
  19. {
  20. /// <summary>
  21. /// Subsription token returned from <see cref="EventBase"/> on subscribe.
  22. /// </summary>
  23. public class SubscriptionToken : IEquatable<SubscriptionToken>
  24. {
  25. private readonly Guid _token;
  26. /// <summary>
  27. /// Initializes a new instance of <see cref="SubscriptionToken"/>.
  28. /// </summary>
  29. public SubscriptionToken()
  30. {
  31. _token = Guid.NewGuid();
  32. }
  33. ///<summary>
  34. ///Indicates whether the current object is equal to another object of the same type.
  35. ///</summary>
  36. ///<returns>
  37. ///<see langword="true"/> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <see langword="false"/>.
  38. ///</returns>
  39. ///<param name="other">An object to compare with this object.</param>
  40. public bool Equals(SubscriptionToken other)
  41. {
  42. if (other == null) return false;
  43. return Equals(_token, other._token);
  44. }
  45. ///<summary>
  46. ///Determines whether the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />.
  47. ///</summary>
  48. ///<returns>
  49. ///true if the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />; otherwise, false.
  50. ///</returns>
  51. ///<param name="obj">The <see cref="T:System.Object" /> to compare with the current <see cref="T:System.Object" />. </param>
  52. ///<exception cref="T:System.NullReferenceException">The <paramref name="obj" /> parameter is null.</exception><filterpriority>2</filterpriority>
  53. public override bool Equals(object obj)
  54. {
  55. if (ReferenceEquals(this, obj)) return true;
  56. return Equals(obj as SubscriptionToken);
  57. }
  58. ///<summary>
  59. ///Serves as a hash function for a particular type.
  60. ///</summary>
  61. ///<returns>
  62. ///A hash code for the current <see cref="T:System.Object" />.
  63. ///</returns>
  64. ///<filterpriority>2</filterpriority>
  65. public override int GetHashCode()
  66. {
  67. return _token.GetHashCode();
  68. }
  69. }
  70. }