PageRenderTime 17ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 1ms 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
18using System;
19
20namespace Microsoft.Practices.Composite.Events
21{
22    /// <summary>
23    /// Subsription token returned from <see cref="EventBase"/> on subscribe.
24    /// </summary>
25    public class SubscriptionToken : IEquatable<SubscriptionToken>
26    {
27        private readonly Guid _token;
28
29        /// <summary>
30        /// Initializes a new instance of <see cref="SubscriptionToken"/>.
31        /// </summary>
32        public SubscriptionToken()
33        {
34            _token = Guid.NewGuid();
35        }
36
37        ///<summary>
38        ///Indicates whether the current object is equal to another object of the same type.
39        ///</summary>
40        ///<returns>
41        ///<see langword="true"/> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <see langword="false"/>.
42        ///</returns>
43        ///<param name="other">An object to compare with this object.</param>
44        public bool Equals(SubscriptionToken other)
45        {
46            if (other == null) return false;
47            return Equals(_token, other._token);
48        }
49
50        ///<summary>
51        ///Determines whether the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />.
52        ///</summary>
53        ///<returns>
54        ///true if the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />; otherwise, false.
55        ///</returns>
56        ///<param name="obj">The <see cref="T:System.Object" /> to compare with the current <see cref="T:System.Object" />. </param>
57        ///<exception cref="T:System.NullReferenceException">The <paramref name="obj" /> parameter is null.</exception><filterpriority>2</filterpriority>
58        public override bool Equals(object obj)
59        {
60            if (ReferenceEquals(this, obj)) return true;
61            return Equals(obj as SubscriptionToken);
62        }
63
64        ///<summary>
65        ///Serves as a hash function for a particular type. 
66        ///</summary>
67        ///<returns>
68        ///A hash code for the current <see cref="T:System.Object" />.
69        ///</returns>
70        ///<filterpriority>2</filterpriority>
71        public override int GetHashCode()
72        {
73            return _token.GetHashCode();
74        }
75    }
76}