Skip to content

Commit

Permalink
Use CallerArgumentExpressionAttribute in throw helpers (#1788)
Browse files Browse the repository at this point in the history
  • Loading branch information
IliaBrahinets authored Feb 2, 2025
1 parent 3f36a8d commit 45d6071
Show file tree
Hide file tree
Showing 72 changed files with 490 additions and 460 deletions.
1 change: 1 addition & 0 deletions src/Magick.NET.Core/Magick.NET.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<Compile Include="../Shared/MemberNotNullAttribute.cs" Link="Helpers/MemberNotNullAttribute.cs" />
<Compile Include="../Shared/NotNullAttribute.cs" Link="Helpers/NotNullAttribute.cs" />
<Compile Include="../Shared/Throw.cs" Link="Helpers/Throw.cs" />
<Compile Include="../Shared/CallerArgumentExpressionAttribute.cs" Link="Helpers/CallerArgumentExpressionAttribute.cs" />
<Compile Include="../Shared/TypeHelper.cs" Link="Helpers/TypeHelper.cs" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET.Core/Profiles/8Bim/EightBimProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public EightBimProfile(Stream stream)
public EightBimProfile(IMagickImage image, byte[] data)
: base("8bim", data)
{
Throw.IfNull(nameof(image), image);
Throw.IfNull(image);

_width = image.Width;
_height = image.Height;
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET.Core/Profiles/8Bim/EightBimValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public override string ToString()
/// <returns>A string that represents the current value with the specified encoding.</returns>
public string ToString(Encoding encoding)
{
Throw.IfNull(nameof(encoding), encoding);
Throw.IfNull(encoding);

return encoding.GetString(_data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET.Core/Profiles/EndianReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class EndianReader

public EndianReader(byte[] data)
{
Throw.IfNullOrEmpty(nameof(data), data);
Throw.IfNullOrEmpty(data);

_data = data;
Index = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET.Core/Profiles/Exif/ExifProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void Rewrite()
/// <typeparam name="TValueType">The data type of the tag.</typeparam>
public void SetValue<TValueType>(ExifTag<TValueType> tag, TValueType value)
{
Throw.IfNull(nameof(value), value);
Throw.IfNull(value);

InitializeValues();
foreach (var exifValue in _data.Values)
Expand Down
12 changes: 6 additions & 6 deletions src/Magick.NET.Core/Profiles/ImageProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public partial class ImageProfile : IImageProfile
/// <param name="data">A byte array containing the profile.</param>
public ImageProfile(string name, byte[] data)
{
Throw.IfNullOrEmpty(nameof(name), name);
Throw.IfNull(nameof(data), data);
Throw.IfNullOrEmpty(name);
Throw.IfNull(data);

Name = name;
_data = Copy(data);
Expand All @@ -34,7 +34,7 @@ public ImageProfile(string name, byte[] data)
/// <param name="stream">A stream containing the profile.</param>
public ImageProfile(string name, Stream stream)
{
Throw.IfNullOrEmpty(nameof(name), name);
Throw.IfNullOrEmpty(name);

Name = name;

Expand All @@ -49,8 +49,8 @@ public ImageProfile(string name, Stream stream)
/// <param name="fileName">The fully qualified name of the profile file, or the relative profile file name.</param>
public ImageProfile(string name, string fileName)
{
Throw.IfNullOrEmpty(nameof(name), name);
Throw.IfNullOrEmpty(nameof(fileName), fileName);
Throw.IfNullOrEmpty(name);
Throw.IfNullOrEmpty(fileName);

Name = name;

Expand All @@ -64,7 +64,7 @@ public ImageProfile(string name, string fileName)
/// <param name="name">The name of the profile.</param>
protected ImageProfile(string name)
{
Throw.IfNullOrEmpty(nameof(name), name);
Throw.IfNullOrEmpty(name);
Name = name;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET.Core/Profiles/Iptc/IptcValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class IptcValue : IIptcValue

internal IptcValue(IptcTag tag, byte[] value)
{
Throw.IfNull(nameof(value), value);
Throw.IfNull(value);

Tag = tag;
_data = value;
Expand Down
6 changes: 3 additions & 3 deletions src/Magick.NET.Core/Profiles/Xmp/XmpProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public XmpProfile(byte[] data)
public XmpProfile(IXPathNavigable document)
: base("xmp")
{
Throw.IfNull(nameof(document), document);
Throw.IfNull(document);

var navigator = document.CreateNavigator();
if (navigator is not null)
Expand All @@ -51,7 +51,7 @@ public XmpProfile(IXPathNavigable document)
public XmpProfile(XDocument document)
: base("xmp")
{
Throw.IfNull(nameof(document), document);
Throw.IfNull(document);

using var memStream = new MemoryStream();
using var writer = CreateXmlWriter(memStream);
Expand Down Expand Up @@ -151,7 +151,7 @@ private static XmlWriter CreateXmlWriter(MemoryStream memStream)

private static byte[] CheckTrailingNULL(byte[] data)
{
Throw.IfNull(nameof(data), data);
Throw.IfNull(data);

var length = data.Length;

Expand Down
10 changes: 5 additions & 5 deletions src/Magick.NET.Core/Types/Density.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ private static string ToString(double x, double y, DensityUnit units)

private void Initialize(string value)
{
Throw.IfNullOrEmpty(nameof(value), value);
Throw.IfNullOrEmpty(value);

var values = value.Split(' ');
Throw.IfTrue(nameof(value), values.Length > 2, "Invalid density specified.");
Throw.IfTrue(values.Length > 2, nameof(value), "Invalid density specified.");

if (values.Length == 2)
{
Expand All @@ -179,15 +179,15 @@ private void Initialize(string value)
}

var xyValues = values[0].Split('x');
Throw.IfTrue(nameof(value), xyValues.Length > 2, "Invalid density specified.");
Throw.IfTrue(xyValues.Length > 2, nameof(value), "Invalid density specified.");

Throw.IfFalse(nameof(value), double.TryParse(xyValues[0], NumberStyles.Number, CultureInfo.InvariantCulture, out var x), "Invalid density specified.");
Throw.IfFalse(double.TryParse(xyValues[0], NumberStyles.Number, CultureInfo.InvariantCulture, out var x), nameof(value), "Invalid density specified.");

double y;
if (xyValues.Length == 1)
y = x;
else
Throw.IfFalse(nameof(value), double.TryParse(xyValues[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y), "Invalid density specified.");
Throw.IfFalse(double.TryParse(xyValues[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y), nameof(value), "Invalid density specified.");

X = x;
Y = y;
Expand Down
8 changes: 4 additions & 4 deletions src/Magick.NET.Core/Types/PointD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public PointD(double x, double y)
public PointD(string value)
: this()
{
Throw.IfNullOrEmpty(nameof(value), value);
Throw.IfNullOrEmpty(value);

Initialize(value);
}
Expand Down Expand Up @@ -108,13 +108,13 @@ public override string ToString()
private void Initialize(string value)
{
var values = value.Split('x');
Throw.IfTrue(nameof(value), values.Length > 2, "Invalid point specified.");
Throw.IfTrue(values.Length > 2, nameof(value), "Invalid point specified.");

Throw.IfFalse(nameof(value), double.TryParse(values[0], NumberStyles.Number, CultureInfo.InvariantCulture, out var x), "Invalid point specified.");
Throw.IfFalse(double.TryParse(values[0], NumberStyles.Number, CultureInfo.InvariantCulture, out var x), nameof(value), "Invalid point specified.");

double y;
if (values.Length == 2)
Throw.IfFalse(nameof(value), double.TryParse(values[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y), "Invalid point specified.");
Throw.IfFalse(double.TryParse(values[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y), nameof(value), "Invalid point specified.");
else
y = x;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class IMagickImageCollectionExtensions
public static Bitmap ToBitmap<TQuantumType>(this IMagickImageCollection<TQuantumType> self)
where TQuantumType : struct, IConvertible
{
Throw.IfNull(nameof(self), self);
Throw.IfNull(self);

if (self.Count == 1)
return self[0].ToBitmap();
Expand All @@ -41,8 +41,8 @@ public static Bitmap ToBitmap<TQuantumType>(this IMagickImageCollection<TQuantum
public static Bitmap ToBitmap<TQuantumType>(this IMagickImageCollection<TQuantumType> self, ImageFormat imageFormat)
where TQuantumType : struct, IConvertible
{
Throw.IfNull(nameof(self), self);
Throw.IfNull(nameof(imageFormat), imageFormat);
Throw.IfNull(self);
Throw.IfNull(imageFormat);

var format = imageFormat.ToMagickFormat();

Expand Down
10 changes: 5 additions & 5 deletions src/Magick.NET.SystemDrawing/IMagickImageExtentions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public static partial class IMagickImageExtentions
public static void Read<TQuantumType>(this IMagickImage<TQuantumType> self, Bitmap bitmap)
where TQuantumType : struct, IConvertible
{
Throw.IfNull(nameof(self), self);
Throw.IfNull(nameof(bitmap), bitmap);
Throw.IfNull(self);
Throw.IfNull(bitmap);

using var memStream = new MemoryStream();
if (IsSupportedImageFormat(bitmap.RawFormat))
Expand Down Expand Up @@ -84,7 +84,7 @@ public static Bitmap ToBitmapWithDensity<TQuantumType>(this IMagickImage<TQuantu
private static Bitmap ToBitmap<TQuantumType>(this IMagickImage<TQuantumType> self, bool withDensity)
where TQuantumType : struct, IConvertible
{
Throw.IfNull(nameof(self), self);
Throw.IfNull(self);

var image = self;

Expand Down Expand Up @@ -133,8 +133,8 @@ private static Bitmap ToBitmap<TQuantumType>(this IMagickImage<TQuantumType> sel
private static Bitmap ToBitmap<TQuantumType>(IMagickImage<TQuantumType> self, ImageFormat imageFormat, bool withDensity)
where TQuantumType : struct, IConvertible
{
Throw.IfNull(nameof(self), self);
Throw.IfNull(nameof(imageFormat), imageFormat);
Throw.IfNull(self);
Throw.IfNull(imageFormat);

var format = imageFormat.ToMagickFormat();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class IMagickImageFactoryExtensions
public static IMagickImage<TQuantumType> Create<TQuantumType>(this IMagickImageFactory<TQuantumType> self, Bitmap bitmap)
where TQuantumType : struct, IConvertible
{
Throw.IfNull(nameof(self), self);
Throw.IfNull(self);

var image = self.Create();
image.Read(bitmap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<ItemGroup>
<Compile Include="../Shared/NotNullAttribute.cs" Link="Helpers/NotNullAttribute.cs" />
<Compile Include="../Shared/Throw.cs" Link="Helpers/Throw.cs" />
<Compile Include="../Shared/CallerArgumentExpressionAttribute.cs" Link="Helpers/CallerArgumentExpressionAttribute.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static BitmapSource ToBitmapSourceWithDensity<TQuantumType>(this IMagickI
private static BitmapSource ToBitmapSource<TQuantumType>(this IMagickImage<TQuantumType> self, bool useDensity)
where TQuantumType : struct, IConvertible
{
Throw.IfNull(nameof(self), self);
Throw.IfNull(self);

var image = self;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ItemGroup>
<Compile Include="../Shared/NotNullAttribute.cs" Link="Helpers/NotNullAttribute.cs" />
<Compile Include="../Shared/Throw.cs" Link="Helpers/Throw.cs" />
<Compile Include="../Shared/CallerArgumentExpressionAttribute.cs" Link="Helpers/CallerArgumentExpressionAttribute.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET/Colors/ColorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class ColorBase : IEquatable<ColorBase?>, IComparable<ColorBase?
/// <param name="color">The color to use.</param>
protected ColorBase(IMagickColor<QuantumType> color)
{
Throw.IfNull(nameof(color), color);
Throw.IfNull(color);

Color = color;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET/Colors/ColorCMYK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public QuantumType Y

private static IMagickColor<QuantumType> CreateColor(string color)
{
Throw.IfNullOrEmpty(nameof(color), color);
Throw.IfNullOrEmpty(color);

if (color[0] == '#')
{
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET/Colors/ColorGray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed class ColorGray : ColorBase
public ColorGray(double shade)
: base(new MagickColor(0, 0, 0))
{
Throw.IfTrue(nameof(shade), shade < 0.0 || shade > 1.0, "Invalid shade specified");
Throw.IfTrue(shade < 0.0 || shade > 1.0, nameof(shade), "Invalid shade specified");

_shade = shade;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Magick.NET/Colors/MagickColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public MagickColor()
/// <param name="color">The color to use.</param>
public MagickColor(IMagickColor<QuantumType> color)
{
Throw.IfNull(nameof(color), color);
Throw.IfNull(color);

R = color.R;
G = color.G;
Expand Down Expand Up @@ -119,7 +119,7 @@ public MagickColor(QuantumType cyan, QuantumType magenta, QuantumType yellow, Qu
/// For example: #F000, #FF000000, #FFFF000000000000.</param>
public MagickColor(string color)
{
Throw.IfNullOrEmpty(nameof(color), color);
Throw.IfNullOrEmpty(color);

if (color.Equals("transparent", StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -134,7 +134,7 @@ public MagickColor(string color)
}

using var instance = NativeMagickColor.Create();
Throw.IfFalse(nameof(color), instance.Initialize(color), "Invalid color specified");
Throw.IfFalse(instance.Initialize(color), nameof(color), "Invalid color specified");
Initialize(instance);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Magick.NET/Defines/MagickDefine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public MagickDefine(MagickFormat format, string name, long value)
/// <param name="value">The value of the define.</param>
public MagickDefine(MagickFormat format, string name, string value)
{
Throw.IfNullOrEmpty(nameof(name), name);
Throw.IfNullOrEmpty(nameof(value), value);
Throw.IfNullOrEmpty(name);
Throw.IfNullOrEmpty(value);

Format = format;
Name = name;
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET/Drawing/Coordinates/DrawableCoordinates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal abstract class DrawableCoordinates<TCoordinateType> : IReadOnlyList<TCo

protected DrawableCoordinates(IEnumerable<TCoordinateType> coordinates, int minCount)
{
Throw.IfNull(nameof(coordinates), coordinates);
Throw.IfNull(coordinates);

_coordinates = DrawableCoordinates<TCoordinateType>.CheckCoordinates(new List<TCoordinateType>(coordinates), minCount);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET/Drawing/DrawableBorderColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed partial class DrawableBorderColor : IDrawableBorderColor<QuantumTy
/// <param name="color">The color of the border.</param>
public DrawableBorderColor(IMagickColor<QuantumType> color)
{
Throw.IfNull(nameof(color), color);
Throw.IfNull(color);

Color = color;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET/Drawing/DrawableClipPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class DrawableClipPath : IDrawableClipPath, IDrawingWand
/// <param name="clipPath">The ID of the clip path.</param>
public DrawableClipPath(string clipPath)
{
Throw.IfNullOrEmpty(nameof(clipPath), clipPath);
Throw.IfNullOrEmpty(clipPath);

ClipPath = clipPath;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET/Drawing/DrawableComposite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public DrawableComposite(double x, double y, double width, double height, Compos

private DrawableComposite(IMagickImage<QuantumType> image)
{
Throw.IfNull(nameof(image), image);
Throw.IfNull(image);

Image = image;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET/Drawing/DrawableFillColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed partial class DrawableFillColor : IDrawableFillColor<QuantumType>,
/// <param name="color">The color to use.</param>
public DrawableFillColor(IMagickColor<QuantumType> color)
{
Throw.IfNull(nameof(color), color);
Throw.IfNull(color);

Color = color;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET/Drawing/DrawableFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public DrawableFont(string family)
/// <param name="stretch">The font stretching type.</param>
public DrawableFont(string family, FontStyleType style, FontWeight weight, FontStretch stretch)
{
Throw.IfNullOrEmpty(nameof(family), family);
Throw.IfNullOrEmpty(family);

Family = family;
Style = style;
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET/Drawing/DrawableStrokeColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed partial class DrawableStrokeColor : IDrawableStrokeColor<QuantumTy
/// <param name="color">The color to use.</param>
public DrawableStrokeColor(IMagickColor<QuantumType> color)
{
Throw.IfNull(nameof(color), color);
Throw.IfNull(color);

Color = color;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Magick.NET/Drawing/DrawableText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class DrawableText : IDrawableText, IDrawingWand
/// <param name="value">The text to draw.</param>
public DrawableText(double x, double y, string value)
{
Throw.IfNullOrEmpty(nameof(value), value);
Throw.IfNullOrEmpty(value);

X = x;
Y = y;
Expand Down
Loading

0 comments on commit 45d6071

Please sign in to comment.