コード例 #1
0
        /// <summary>
        /// Gets the value of the given field from the data reader or the
        /// default for the object type.
        /// </summary>
        /// <typeparam name="T">Type of object.</typeparam>
        /// <param name="dataRecord">Current IDataRecord object from extension method.</param>
        /// <param name="index">Index of field within IDataRecord.</param>
        /// <param name="defaultValue">Value to use if null field value.</param>
        /// <returns>The given field's value or the given default.</returns>
        public static T GetValueOrDefault <T>(this IDataRecord dataRecord, int index, T defaultValue)
        {
            if (dataRecord == null)
            {
                throw new ArgumentNullException("dataRecord");
            }

            object value = dataRecord[index];

            return(DatabaseValueParser.GetValueOrDefault(value, defaultValue));
        }
コード例 #2
0
        /// <summary>
        /// Gets the value of the given field from the data reader or the
        /// default for the object type.
        /// </summary>
        /// <typeparam name="T">Type of object.</typeparam>
        /// <param name="dataRecord">Current IDataRecord object from extension method.</param>
        /// <param name="name">Name of field within IDataRecord.</param>
        /// <returns>The given field's value or the default for the object type.</returns>
        public static T GetValueOrDefault <T>(this IDataRecord dataRecord, string name)
        {
            if (dataRecord == null)
            {
                throw new ArgumentNullException("dataRecord");
            }

            object value = dataRecord[name];

            return(DatabaseValueParser.GetValueOrDefault <T>(value));
        }