System.Data.Common.DbConnectionStringBuilder.TryGetValue C# (CSharp) Метод

TryGetValue() публичный Метод

public TryGetValue ( string keyword, object &value ) : bool
keyword string
value object
Результат bool
        public virtual bool TryGetValue(string keyword, out object value)
        {
            ADP.CheckArgumentNull(keyword, nameof(keyword));
            return CurrentValues.TryGetValue(keyword, out value);
        }

Usage Example

Пример #1
0
        /// <summary>
        /// This function returns login and password of user for a passed NpgsqlConnection
        /// </summary>
        /// <param name="connection">the current opened DbConnection</param>
        /// <param name="login">returned login corresponding to the NpgsqlConnection passed</param>
        /// <param name="password">returned password corresponding to the NpgsqlConnection passed</param>
        /// <returns>true if succeed, false otherwise (connection null or not opened)</returns>
        public static bool GetConnectionInformationsFrom(
                                      IDbConnection connection,
                                      out string login,
                                      out string password)
        {
            login = string.Empty;
            password = string.Empty;

            if ((connection != null) && (connection.State == System.Data.ConnectionState.Open))
            {
                DbConnectionStringBuilder builder = new DbConnectionStringBuilder();
                builder.ConnectionString = connection.ConnectionString;

                if (builder != null)
                {
                    object value = null;
                    bool result = builder.TryGetValue("User Id", out value);
                    if (result)
                    {
                        login = value.ToString();
                    }

                    result &= builder.TryGetValue("Password", out value);
                    if (result)
                    {
                        password = value.ToString();
                    }

                    builder.Clear();
                    return result;
                }
            }

            return false;
        }
All Usage Examples Of System.Data.Common.DbConnectionStringBuilder::TryGetValue