From 82ac8a720abac930e0985119bcf30ea7fa361d60 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Thu, 10 May 2018 07:59:51 -0700 Subject: [PATCH] Rename Gaurd.NotNullOrEmpty to NotNullOrWhiteSpace to match behavior & cleanup messages. Also remove the unused message arguments. --- src/ImageSharp/Common/Helpers/Guard.cs | 67 ++++++++----------- src/ImageSharp/MetaData/ImageProperty.cs | 2 +- .../PixelFormats/ColorBuilder{TPixel}.cs | 2 +- 3 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs index 9f0a46f80..603cf566f 100644 --- a/src/ImageSharp/Common/Helpers/Guard.cs +++ b/src/ImageSharp/Common/Helpers/Guard.cs @@ -15,16 +15,15 @@ namespace SixLabors.ImageSharp internal static class Guard { /// - /// Verifies, that the method parameter with specified object value is not null - /// and throws an exception if it is found to be so. + /// Ensures that the value is not null. /// - /// The target object, which cannot be null. + /// The target object, which cannot be null. /// The name of the parameter that is to be checked. /// The error message, if any to add to the exception. - /// is null - public static void NotNull(object target, string parameterName, string message = "") + /// is null + public static void NotNull(object value, string parameterName, string message = "") { - if (target == null) + if (value == null) { if (!string.IsNullOrWhiteSpace(message)) { @@ -36,57 +35,49 @@ namespace SixLabors.ImageSharp } /// - /// Verifies, that the string method parameter with specified object value and message - /// is not null, not empty and does not contain only blanks and throws an exception - /// if the object is null. + /// Ensures that the target value is not null, empty, or whitespace. /// - /// The target string, which should be checked against being null or empty. + /// The target string, which should be checked against being null or empty. /// Name of the parameter. - /// The error message, if any to add to the exception. - /// is null. - /// is empty or contains only blanks. - public static void NotNullOrEmpty(string target, string parameterName, string message = "") + /// is null. + /// is empty or contains only blanks. + public static void NotNullOrWhiteSpace(string value, string parameterName) { - NotNull(target, parameterName, message); - - if (string.IsNullOrWhiteSpace(target)) + if (value == null) { - if (!string.IsNullOrWhiteSpace(message)) - { - throw new ArgumentException(message, parameterName); - } + throw new ArgumentNullException(parameterName); + } - throw new ArgumentException("Value cannot be null or empty and cannot contain only blanks.", parameterName); + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Must not be empty or whitespace.", parameterName); } } /// - /// Verifies, that the enumeration is not null and not empty. + /// Ensures that the enumeration is not null or empty. /// - /// The type of objects in the - /// The target enumeration, which should be checked against being null or empty. + /// The type of objects in the + /// The target enumeration, which should be checked against being null or empty. /// Name of the parameter. /// The error message, if any to add to the exception. - /// is null. - /// is empty. - public static void NotNullOrEmpty(IEnumerable target, string parameterName, string message = "") + /// is null. + /// is empty. + public static void NotNullOrEmpty(IEnumerable value, string parameterName) { - NotNull(target, parameterName, message); - - if (!target.Any()) + if (value == null) { - if (!string.IsNullOrWhiteSpace(message)) - { - throw new ArgumentException(message, parameterName); - } + throw new ArgumentNullException(parameterName); + } - throw new ArgumentException("Value cannot be empty.", parameterName); + if (!value.Any()) + { + throw new ArgumentException("Must not be empty.", parameterName); } } /// - /// Verifies that the specified value is less than a maximum value - /// and throws an exception if it is not. + /// Ensures that the specified value is less than a maximum value. /// /// The target value, which should be validated. /// The maximum value. diff --git a/src/ImageSharp/MetaData/ImageProperty.cs b/src/ImageSharp/MetaData/ImageProperty.cs index c67c1f3cf..3e0cccd42 100644 --- a/src/ImageSharp/MetaData/ImageProperty.cs +++ b/src/ImageSharp/MetaData/ImageProperty.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.MetaData /// The value of the property. public ImageProperty(string name, string value) { - Guard.NotNullOrEmpty(name, nameof(name)); + Guard.NotNullOrWhiteSpace(name, nameof(name)); this.Name = name; this.Value = value; diff --git a/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs b/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs index f5ebdb3fd..1e7645aeb 100644 --- a/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs @@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Returns a that represents the color defined by the provided RGBA heax string. public static TPixel FromHex(string hex) { - Guard.NotNullOrEmpty(hex, nameof(hex)); + Guard.NotNullOrWhiteSpace(hex, nameof(hex)); hex = ToRgbaHex(hex); uint packedValue;