コード例 #1
0
        /// <summary>
        /// Create a new IngresConnectionStringBuilder with
        /// an initial connection string.
        /// </summary>
        /// <param name="connectionString"></param>
        public IngresConnectionStringBuilder(string connectionString)
        {
            _items = (DictionaryEntry[])
                     ConnectStringConfig.ConnectBuilderKeywords.Clone();

            this.ConnectionString = connectionString;

            _connectStringConfig =
                ConnectStringConfig.ParseConnectionString(connectionString);
        }
コード例 #2
0
        /// <summary>
        /// Get/set the value associated with the specified key.
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public override object this [String keyword]
        {
            // Look up the ordinal for and return
            // the value at that position.
            get
            {
                int i = GetOrdinal(keyword);
                return(_items[i].Value);
            }
            set
            {
                int i = GetOrdinal(keyword);

                if (value == null)
                {
                    this.Remove(keyword);
                    return;
                }

                Object nativeValue = value;                  // assume no conversion needed

                TypeCode sourceTypeCode = Type.GetTypeCode(value.GetType());
                Type     targetType     =
                    ConnectStringConfig.ConnectBuilderKeywords[i].Value.GetType();
                TypeCode targetTypeCode = Type.GetTypeCode(targetType);

                if (targetTypeCode != sourceTypeCode)
                {
                    switch (targetTypeCode)
                    {
                    case TypeCode.Int32:
                        nativeValue = Int32.Parse(value.ToString());
                        break;

                    case TypeCode.Boolean:
                        String valueString = value.ToString().Trim();
                        String valueLower  = ToInvariantLower(valueString);

                        // Catch yes/no literals that Boolean.Parse doesn't
                        if (valueLower == "yes" || valueLower == "1")
                        {
                            nativeValue = true;
                            value       = "true";
                            break;
                        }
                        if (valueLower == "no" || valueLower == "0")
                        {
                            nativeValue = false;
                            value       = "false";
                            break;
                        }
                        nativeValue = Boolean.Parse(valueString);
                        break;

                    case TypeCode.String:
                        nativeValue = value.ToString();
                        break;

                    default:
                        throw new System.InvalidOperationException(
                                  "IngresConnectionStringBuilder internal error: " +
                                  "unexpected Type for keyword '" + keyword + "'.");
                    }             // end switch
                }                 // end if (targetTypeCode != sourceTypeCode)

                string connectionString = keyword + "=" +
                                          (value != null ? value.ToString() : "");
                ConnectStringConfig connectStringConfig =
                    ConnectStringConfig.ParseConnectionString(connectionString);
                if (connectStringConfig.Count > 1)
                {
                    throw new ArgumentException("Invalid keyword/value pair: '" +
                                                connectionString + "'.");
                }

                base[_items[i].Key.ToString()] = nativeValue;                  // Standardize key
                _items[i].Value = nativeValue;
            }
        }