DALs.Sql/Extractions/DataReaderExtractions.cs
/// <summary>
/// Gets reader value by index.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="reader">The reader.</param>
/// <param name="index">The index.</param>
/// <param name="defaultVal">The default value.</param>
/// <returns>T.</returns>
Gets reader value by index.
Gets reader value by index .
public static T Get<T>(this IDataReader reader, int index, T defaultVal = default(T))
        {
            if (reader.IsDBNull(index))
            {
                return defaultVal;
            }
            var result = reader[index];
            try
            {
                return (T)result;
            }
            catch (InvalidCastException)
            {
                Trace.TraceError("Cannot cast from {0} to {1}"
                    , result.GetType().ToString(), defaultVal.GetType().ToString());
                throw;
            }
        }
public static T Get < T > ( this IDataReader reader , int index , T defaultVal = default ( T ) ) { if ( reader . IsDBNull ( index ) ) { return defaultVal ; } var result = reader [ index ] ; try { return ( T ) result ; } catch ( InvalidCastException ) { Trace . TraceError ( " " , result . GetType ( ) . ToString ( ) , defaultVal . GetType ( ) . ToString ( ) ) ; throw ; } }
Gets reader value by index.
Gets reader value by index .
None
IDataReader
this
index
int
None
defaultVal
T
The default value.
The default value .
reader
None
typeparam
None