Skip to content

Instantly share code, notes, and snippets.

@KEMBL
Last active August 23, 2017 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KEMBL/9ea21506f09bf1129b199490536465b8 to your computer and use it in GitHub Desktop.
Save KEMBL/9ea21506f09bf1129b199490536465b8 to your computer and use it in GitHub Desktop.
How arguments could be checked
// 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