Last active
August 23, 2017 15:26
-
-
Save KEMBL/9ea21506f09bf1129b199490536465b8 to your computer and use it in GitHub Desktop.
How arguments could be checked
This file contains 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
// ORIGINAL | |
public async Task UploadBlobFromFile(string filePath, string containerName, string destinationPath) | |
{ | |
if (!File.Exists(filePath)) | |
{ | |
throw new FileNotFoundException(filePath); | |
} | |
CloudBlobContainer container = await GetBlobContainer(containerName); | |
CloudBlockBlob blob = GetBlockBlobReference(container, destinationPath); | |
await blob.UploadFromFileAsync(filePath); | |
} | |
// NEW | |
public async Task UploadBlobFromFile(string filePath, string containerName, string destinationPath) | |
{ | |
if (filePath == null) | |
throw new ArgumentNullException(nameof(filePath), "Argument should be defined!"); | |
// OR | |
if (string.IsNullOrEmpty(filePath)) | |
throw new ArgumentException("Argument should be defined!", nameof(filePath)); | |
if (!File.Exists(filePath)) | |
{ | |
throw new FileNotFoundException(filePath); | |
} | |
CloudBlobContainer container = await GetBlobContainer(containerName); | |
CloudBlockBlob blob = GetBlockBlobReference(container, destinationPath); | |
await blob.UploadFromFileAsync(filePath); | |
} | |
// The same with annotations | |
using JetBrains.Annotations; | |
public async Task UploadBlobFromFile([NotNull] string filePath, [NotNull] string containerName, string destinationPath) | |
{ | |
if (filePath == null) | |
throw new ArgumentNullException(nameof(filePath), "Argument should be defined!"); | |
// OR | |
if (string.IsNullOrEmpty(filePath)) | |
throw new ArgumentException("Argument should be defined!", nameof(filePath)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment