//------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // // harsudan // yuronhe //------------------------------------------------------------------------------ using System; using System.Diagnostics; namespace System.Data.ProviderBase { /// /// Represents the key of dbConnectionPoolAuthenticationContext. /// All data members should be immutable and so, hashCode is pre-computed. /// sealed internal class DbConnectionPoolAuthenticationContextKey { /// /// Security Token Service Authority. /// private readonly string _stsAuthority; /// /// Service Principal Name. /// private readonly string _servicePrincipalName; /// /// Pre-Computed Hash Code. /// private readonly int _hashCode; internal string StsAuthority { get { return _stsAuthority; } } internal string ServicePrincipalName { get { return _servicePrincipalName; } } /// /// Constructor for the type. /// /// Token Endpoint URL /// SPN representing the SQL service in an active directory. internal DbConnectionPoolAuthenticationContextKey(string stsAuthority, string servicePrincipalName) { Debug.Assert(!string.IsNullOrWhiteSpace(stsAuthority)); Debug.Assert(!string.IsNullOrWhiteSpace(servicePrincipalName)); _stsAuthority = stsAuthority; _servicePrincipalName = servicePrincipalName; // Pre-compute hash since data members are not going to change. _hashCode = ComputeHashCode(); } /// /// Override the default Equals implementation. /// /// /// public override bool Equals(object obj) { if (obj == null) { return false; } DbConnectionPoolAuthenticationContextKey otherKey = obj as DbConnectionPoolAuthenticationContextKey; if (otherKey == null) { return false; } return (String.Equals(StsAuthority, otherKey.StsAuthority, StringComparison.InvariantCultureIgnoreCase) && String.Equals(ServicePrincipalName, otherKey.ServicePrincipalName, StringComparison.InvariantCultureIgnoreCase)); } /// /// Override the default GetHashCode implementation. /// /// public override int GetHashCode() { return _hashCode; } /// /// Compute the hash code for this object. /// /// private int ComputeHashCode() { int hashCode = 33; unchecked { hashCode = (hashCode * 17) + StsAuthority.GetHashCode(); hashCode = (hashCode * 17) + ServicePrincipalName.GetHashCode(); } return hashCode; } } }