1 //------------------------------------------------------------------------------
2 // <copyright file="ConnectionPoolKey.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
9 namespace System.Data.SqlClient
13 using System.Collections;
14 using System.Data.Common;
15 using System.Diagnostics;
17 // SqlConnectionPoolKey: Implementation of a key to connection pool groups for specifically to be used for SqlConnection
18 // Connection string and SqlCredential are used as a key
19 internal class SqlConnectionPoolKey : DbConnectionPoolKey, ICloneable
21 private SqlCredential _credential;
22 private int _hashValue;
23 private readonly string _accessToken;
25 internal SqlConnectionPoolKey(string connectionString, SqlCredential credential, string accessToken) : base(connectionString)
27 Debug.Assert(_credential == null || _accessToken == null, "Credential and AccessToken can't have the value at the same time.");
28 _credential = credential;
29 _accessToken = accessToken;
33 private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base (key)
35 _credential = key.Credential;
36 _accessToken = key.AccessToken;
40 object ICloneable.Clone()
42 return new SqlConnectionPoolKey(this);
45 internal override string ConnectionString
49 return base.ConnectionString;
54 base.ConnectionString = value;
59 internal SqlCredential Credential
67 internal string AccessToken
75 public override bool Equals(object obj)
77 SqlConnectionPoolKey key = obj as SqlConnectionPoolKey;
79 return (key != null && _credential == key._credential && ConnectionString == key.ConnectionString && Object.ReferenceEquals(_accessToken, key._accessToken));
82 public override int GetHashCode()
87 private void CalculateHashCode()
89 _hashValue = base.GetHashCode();
91 if (_credential != null)
95 _hashValue = _hashValue * 17 + _credential.GetHashCode();
98 else if (_accessToken != null)
102 _hashValue = _hashValue * 17 + _accessToken.GetHashCode();