Created
March 30, 2016 11:22
-
-
Save aleksandrzak-rafal/132215452189b0edf18139394aaac80d to your computer and use it in GitHub Desktop.
Extension method for OdbcDataReader to get rid of null checking when calling Get functions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static T SafeGet<T>(this OdbcDataReader reader, int colIndex) | |
| { | |
| if (!reader.IsDBNull(colIndex)) | |
| { | |
| return (T)reader.GetValue(colIndex); | |
| } | |
| else | |
| { | |
| return default(T); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment