Language: C#
Compare guard code styles
public static void Copy(string sourceDirName, string destDirName, bool excludeSubdirectories) { // Style #1: fluent Guard.MethodArgument("sourceDirName").IsNotNullOrEmpty(sourceDirName); Guard.MethodArgument("destDirName").IsNotNullOrEmpty(destDirName, "The destination directory is required!"); // Style #2: lambdas and expressions Guard.Argument.IsNotNullOrWhiteSpace(()=>sourceDirName); Guard.Argument.IsNotNullOrWhiteSpace(()=>destDirName, "The destination directory is required!"); Guard.Against<IOException>(!System.IO.Directory.Exists(sourceDirName), "Source directory was not found."); // TODO: ... }
Tags:
Description:
Going with a slight variation on Style #1:
Guard.Argument("sourceDirName").IsNotNullOrEmpty(sourceDirName);
The reason for this is that using Expressions to extract the argument name works in C# but not in VB.NET and I'd rather not rely on a compiler feature for such a minimal (IMO) gain.
Guard.Argument("sourceDirName").IsNotNullOrEmpty(sourceDirName);
The reason for this is that using Expressions to extract the argument name works in C# but not in VB.NET and I'd rather not rely on a compiler feature for such a minimal (IMO) gain.
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search


Going with a slight variation on Style #1:
Guard.Argument("sourceDirName").IsNotNullOrEmpty(sourceDirName);
The reason for this is that using Expressions to extract the argument name works in C# but not in VB.NET and I rather not rely on a compiler feature for such a minimal (IMO) gain.