code_junkie

Should I make sure arguments aren't null before using them in a function?

Nov 11th, 2011
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. Public Shared Function GenerateHash(ByVal FilePath As IO.FileInfo) As String
  2. If (FilePath Is Nothing) Then
  3. Throw New ArgumentNullException("FilePath")
  4. End If
  5.  
  6. Dim _sha As New Security.Cryptography.MD5CryptoServiceProvider
  7. Dim _Hash = Convert.ToBase64String(_sha.ComputeHash(New IO.FileStream(FilePath.FullName, IO.FileMode.Open, IO.FileAccess.Read)))
  8. Return _Hash
  9. End Function
Add Comment
Please, Sign In to add comment