Beispiel #1
0
        public void GetValueOrNull_NullString()
        {
            string target = null;
            string actual = DatabaseValueParser.GetValueOrNull <string>(target);

            Assert.Null(actual);
        }
        /// <summary>
        /// Gets the value of the given field from the data reader or null.
        /// </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 null.</returns>
        public static T GetValueOrNull <T>(this IDataRecord dataRecord, string name)
        {
            if (dataRecord == null)
            {
                throw new ArgumentNullException(nameof(dataRecord));
            }

            object value = dataRecord[name];

            return(DatabaseValueParser.GetValueOrNull <T>(value));
        }
Beispiel #3
0
        public void GetValueOrNull_NonNullString()
        {
            string actual = DatabaseValueParser.GetValueOrNull <string>("abc123");

            Assert.Equal("abc123", actual);
        }