PageRenderTime 13ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/V2.2/trunk/CAL/Desktop/Composite/Events/SubscriptionToken.cs

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