Esempio n. 1
0
        //
        // Summary:
        //     Removes the System.Data.Common.DbParameter object with the specified name
        //     from the collection.
        //
        // Parameters:
        //   parameterName:
        //     The name of the System.Data.Common.DbParameter object to remove.
        public override void RemoveAt(string parameterName)
        {
#if CODECONTRACTS
            Contract.Assume(parameterName != null);
#endif

            if (!string.IsNullOrEmpty(parameterName))
            {
                int    ret;
                string canonical = PqsqlParameter.CanonicalParameterName(parameterName);

                if (mLookup.TryGetValue(canonical, out ret) && ret != -1)
                {
                    mParamList.RemoveAt(ret);

                    mLookup.Remove(canonical);

                    // update lookup index
                    foreach (KeyValuePair <string, int> kv in mLookup.Where(kv => kv.Value > ret).ToArray())
                    {
                        mLookup[kv.Key] = kv.Value - 1;
                    }

                    return;
                }
            }

            throw new KeyNotFoundException("Could not find parameter name " + parameterName);
        }
Esempio n. 2
0
        //
        // Summary:
        //     Returns the index of the System.Data.Common.DbParameter object with the specified
        //     name.
        //
        // Parameters:
        //   parameterName:
        //     The name of the System.Data.Common.DbParameter object in the collection.
        //
        // Returns:
        //     The index of the System.Data.Common.DbParameter object with the specified
        //     name.
        public override int IndexOf(string parameterName)
        {
#if CODECONTRACTS
            Contract.Ensures(Contract.Result <int>() >= -1);
            Contract.Ensures(Contract.Result <int>() < Count);
#endif

            int ret;
            if (!string.IsNullOrEmpty(parameterName) &&
                mLookup.TryGetValue(PqsqlParameter.CanonicalParameterName(parameterName), out ret))
            {
                return(ret < -1 ? -1 : ret);
            }

            return(-1);
        }