예제 #1
0
        /// <summary>
        /// Gets the index for a column name
        /// </summary>
        /// <param name="columnName">Column name (case insensitive)</param>
        /// <returns>Index for the specified column name</returns>
        private int GetColumnIndex(string columnName)
        {
            if (ColumnIndex is null)
            {
                ColumnIndex = new Dictionary <string, int>(SqlDataReader.FieldCount);
            }

            if (ColumnIndex.TryGetValue(columnName, out int index))
            {
                return(index);
            }

            try
            {
                index = SqlDataReader.GetOrdinal(columnName);

                ColumnIndex[columnName] = index;

                return(index);
            }
            catch (IndexOutOfRangeException)
            {
                throw new ArgumentOutOfRangeException(
                          paramName: nameof(columnName),
                          message: string.Format(DBSqlServerLocalizedText.DBSqlServerDataReader_ColumnNotFound, columnName));
            }
        }
예제 #2
0
 public T GetValue <T>(object[] rowValues, string columnName)
 {
     if (ColumnIndex.TryGetValue(columnName, out var index) && rowValues.Length > index)
     {
         return((T)rowValues[index]);
     }
     return(default(T));
 }