Skip to content

Commit 45d6071

Browse files
Use CallerArgumentExpressionAttribute in throw helpers (#1788)
1 parent 3f36a8d commit 45d6071

File tree

72 files changed

+490
-460
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+490
-460
lines changed

src/Magick.NET.Core/Magick.NET.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<Compile Include="../Shared/MemberNotNullAttribute.cs" Link="Helpers/MemberNotNullAttribute.cs" />
2222
<Compile Include="../Shared/NotNullAttribute.cs" Link="Helpers/NotNullAttribute.cs" />
2323
<Compile Include="../Shared/Throw.cs" Link="Helpers/Throw.cs" />
24+
<Compile Include="../Shared/CallerArgumentExpressionAttribute.cs" Link="Helpers/CallerArgumentExpressionAttribute.cs" />
2425
<Compile Include="../Shared/TypeHelper.cs" Link="Helpers/TypeHelper.cs" />
2526
</ItemGroup>
2627

src/Magick.NET.Core/Profiles/8Bim/EightBimProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public EightBimProfile(Stream stream)
5959
public EightBimProfile(IMagickImage image, byte[] data)
6060
: base("8bim", data)
6161
{
62-
Throw.IfNull(nameof(image), image);
62+
Throw.IfNull(image);
6363

6464
_width = image.Width;
6565
_height = image.Height;

src/Magick.NET.Core/Profiles/8Bim/EightBimValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public override string ToString()
100100
/// <returns>A string that represents the current value with the specified encoding.</returns>
101101
public string ToString(Encoding encoding)
102102
{
103-
Throw.IfNull(nameof(encoding), encoding);
103+
Throw.IfNull(encoding);
104104

105105
return encoding.GetString(_data);
106106
}

src/Magick.NET.Core/Profiles/EndianReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal sealed class EndianReader
1111

1212
public EndianReader(byte[] data)
1313
{
14-
Throw.IfNullOrEmpty(nameof(data), data);
14+
Throw.IfNullOrEmpty(data);
1515

1616
_data = data;
1717
Index = 0;

src/Magick.NET.Core/Profiles/Exif/ExifProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public void Rewrite()
173173
/// <typeparam name="TValueType">The data type of the tag.</typeparam>
174174
public void SetValue<TValueType>(ExifTag<TValueType> tag, TValueType value)
175175
{
176-
Throw.IfNull(nameof(value), value);
176+
Throw.IfNull(value);
177177

178178
InitializeValues();
179179
foreach (var exifValue in _data.Values)

src/Magick.NET.Core/Profiles/ImageProfile.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public partial class ImageProfile : IImageProfile
2020
/// <param name="data">A byte array containing the profile.</param>
2121
public ImageProfile(string name, byte[] data)
2222
{
23-
Throw.IfNullOrEmpty(nameof(name), name);
24-
Throw.IfNull(nameof(data), data);
23+
Throw.IfNullOrEmpty(name);
24+
Throw.IfNull(data);
2525

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

3939
Name = name;
4040

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

5555
Name = name;
5656

@@ -64,7 +64,7 @@ public ImageProfile(string name, string fileName)
6464
/// <param name="name">The name of the profile.</param>
6565
protected ImageProfile(string name)
6666
{
67-
Throw.IfNullOrEmpty(nameof(name), name);
67+
Throw.IfNullOrEmpty(name);
6868
Name = name;
6969
}
7070

src/Magick.NET.Core/Profiles/Iptc/IptcValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public sealed class IptcValue : IIptcValue
1616

1717
internal IptcValue(IptcTag tag, byte[] value)
1818
{
19-
Throw.IfNull(nameof(value), value);
19+
Throw.IfNull(value);
2020

2121
Tag = tag;
2222
_data = value;

src/Magick.NET.Core/Profiles/Xmp/XmpProfile.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public XmpProfile(byte[] data)
3131
public XmpProfile(IXPathNavigable document)
3232
: base("xmp")
3333
{
34-
Throw.IfNull(nameof(document), document);
34+
Throw.IfNull(document);
3535

3636
var navigator = document.CreateNavigator();
3737
if (navigator is not null)
@@ -51,7 +51,7 @@ public XmpProfile(IXPathNavigable document)
5151
public XmpProfile(XDocument document)
5252
: base("xmp")
5353
{
54-
Throw.IfNull(nameof(document), document);
54+
Throw.IfNull(document);
5555

5656
using var memStream = new MemoryStream();
5757
using var writer = CreateXmlWriter(memStream);
@@ -151,7 +151,7 @@ private static XmlWriter CreateXmlWriter(MemoryStream memStream)
151151

152152
private static byte[] CheckTrailingNULL(byte[] data)
153153
{
154-
Throw.IfNull(nameof(data), data);
154+
Throw.IfNull(data);
155155

156156
var length = data.Length;
157157

src/Magick.NET.Core/Types/Density.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ private static string ToString(double x, double y, DensityUnit units)
163163

164164
private void Initialize(string value)
165165
{
166-
Throw.IfNullOrEmpty(nameof(value), value);
166+
Throw.IfNullOrEmpty(value);
167167

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

171171
if (values.Length == 2)
172172
{
@@ -179,15 +179,15 @@ private void Initialize(string value)
179179
}
180180

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

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

186186
double y;
187187
if (xyValues.Length == 1)
188188
y = x;
189189
else
190-
Throw.IfFalse(nameof(value), double.TryParse(xyValues[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y), "Invalid density specified.");
190+
Throw.IfFalse(double.TryParse(xyValues[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y), nameof(value), "Invalid density specified.");
191191

192192
X = x;
193193
Y = y;

src/Magick.NET.Core/Types/PointD.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public PointD(double x, double y)
3939
public PointD(string value)
4040
: this()
4141
{
42-
Throw.IfNullOrEmpty(nameof(value), value);
42+
Throw.IfNullOrEmpty(value);
4343

4444
Initialize(value);
4545
}
@@ -108,13 +108,13 @@ public override string ToString()
108108
private void Initialize(string value)
109109
{
110110
var values = value.Split('x');
111-
Throw.IfTrue(nameof(value), values.Length > 2, "Invalid point specified.");
111+
Throw.IfTrue(values.Length > 2, nameof(value), "Invalid point specified.");
112112

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

115115
double y;
116116
if (values.Length == 2)
117-
Throw.IfFalse(nameof(value), double.TryParse(values[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y), "Invalid point specified.");
117+
Throw.IfFalse(double.TryParse(values[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y), nameof(value), "Invalid point specified.");
118118
else
119119
y = x;
120120

src/Magick.NET.SystemDrawing/IMagickImageCollectionExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static class IMagickImageCollectionExtensions
2222
public static Bitmap ToBitmap<TQuantumType>(this IMagickImageCollection<TQuantumType> self)
2323
where TQuantumType : struct, IConvertible
2424
{
25-
Throw.IfNull(nameof(self), self);
25+
Throw.IfNull(self);
2626

2727
if (self.Count == 1)
2828
return self[0].ToBitmap();
@@ -41,8 +41,8 @@ public static Bitmap ToBitmap<TQuantumType>(this IMagickImageCollection<TQuantum
4141
public static Bitmap ToBitmap<TQuantumType>(this IMagickImageCollection<TQuantumType> self, ImageFormat imageFormat)
4242
where TQuantumType : struct, IConvertible
4343
{
44-
Throw.IfNull(nameof(self), self);
45-
Throw.IfNull(nameof(imageFormat), imageFormat);
44+
Throw.IfNull(self);
45+
Throw.IfNull(imageFormat);
4646

4747
var format = imageFormat.ToMagickFormat();
4848

src/Magick.NET.SystemDrawing/IMagickImageExtentions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public static partial class IMagickImageExtentions
2424
public static void Read<TQuantumType>(this IMagickImage<TQuantumType> self, Bitmap bitmap)
2525
where TQuantumType : struct, IConvertible
2626
{
27-
Throw.IfNull(nameof(self), self);
28-
Throw.IfNull(nameof(bitmap), bitmap);
27+
Throw.IfNull(self);
28+
Throw.IfNull(bitmap);
2929

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

8989
var image = self;
9090

@@ -133,8 +133,8 @@ private static Bitmap ToBitmap<TQuantumType>(this IMagickImage<TQuantumType> sel
133133
private static Bitmap ToBitmap<TQuantumType>(IMagickImage<TQuantumType> self, ImageFormat imageFormat, bool withDensity)
134134
where TQuantumType : struct, IConvertible
135135
{
136-
Throw.IfNull(nameof(self), self);
137-
Throw.IfNull(nameof(imageFormat), imageFormat);
136+
Throw.IfNull(self);
137+
Throw.IfNull(imageFormat);
138138

139139
var format = imageFormat.ToMagickFormat();
140140

src/Magick.NET.SystemDrawing/IMagickImageFactoryExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static class IMagickImageFactoryExtensions
2222
public static IMagickImage<TQuantumType> Create<TQuantumType>(this IMagickImageFactory<TQuantumType> self, Bitmap bitmap)
2323
where TQuantumType : struct, IConvertible
2424
{
25-
Throw.IfNull(nameof(self), self);
25+
Throw.IfNull(self);
2626

2727
var image = self.Create();
2828
image.Read(bitmap);

src/Magick.NET.SystemDrawing/Magick.NET.SystemDrawing.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<ItemGroup>
2727
<Compile Include="../Shared/NotNullAttribute.cs" Link="Helpers/NotNullAttribute.cs" />
2828
<Compile Include="../Shared/Throw.cs" Link="Helpers/Throw.cs" />
29+
<Compile Include="../Shared/CallerArgumentExpressionAttribute.cs" Link="Helpers/CallerArgumentExpressionAttribute.cs" />
2930
</ItemGroup>
3031

3132
<ItemGroup>

src/Magick.NET.SystemWindowsMedia/IMagickImageExtentions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static BitmapSource ToBitmapSourceWithDensity<TQuantumType>(this IMagickI
3535
private static BitmapSource ToBitmapSource<TQuantumType>(this IMagickImage<TQuantumType> self, bool useDensity)
3636
where TQuantumType : struct, IConvertible
3737
{
38-
Throw.IfNull(nameof(self), self);
38+
Throw.IfNull(self);
3939

4040
var image = self;
4141

src/Magick.NET.SystemWindowsMedia/Magick.NET.SystemWindowsMedia.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<ItemGroup>
2020
<Compile Include="../Shared/NotNullAttribute.cs" Link="Helpers/NotNullAttribute.cs" />
2121
<Compile Include="../Shared/Throw.cs" Link="Helpers/Throw.cs" />
22+
<Compile Include="../Shared/CallerArgumentExpressionAttribute.cs" Link="Helpers/CallerArgumentExpressionAttribute.cs" />
2223
</ItemGroup>
2324

2425
<ItemGroup>

src/Magick.NET/Colors/ColorBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public abstract class ColorBase : IEquatable<ColorBase?>, IComparable<ColorBase?
2626
/// <param name="color">The color to use.</param>
2727
protected ColorBase(IMagickColor<QuantumType> color)
2828
{
29-
Throw.IfNull(nameof(color), color);
29+
Throw.IfNull(color);
3030

3131
Color = color;
3232
}

src/Magick.NET/Colors/ColorCMYK.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public QuantumType Y
163163

164164
private static IMagickColor<QuantumType> CreateColor(string color)
165165
{
166-
Throw.IfNullOrEmpty(nameof(color), color);
166+
Throw.IfNullOrEmpty(color);
167167

168168
if (color[0] == '#')
169169
{

src/Magick.NET/Colors/ColorGray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public sealed class ColorGray : ColorBase
2727
public ColorGray(double shade)
2828
: base(new MagickColor(0, 0, 0))
2929
{
30-
Throw.IfTrue(nameof(shade), shade < 0.0 || shade > 1.0, "Invalid shade specified");
30+
Throw.IfTrue(shade < 0.0 || shade > 1.0, nameof(shade), "Invalid shade specified");
3131

3232
_shade = shade;
3333
}

src/Magick.NET/Colors/MagickColor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public MagickColor()
3434
/// <param name="color">The color to use.</param>
3535
public MagickColor(IMagickColor<QuantumType> color)
3636
{
37-
Throw.IfNull(nameof(color), color);
37+
Throw.IfNull(color);
3838

3939
R = color.R;
4040
G = color.G;
@@ -119,7 +119,7 @@ public MagickColor(QuantumType cyan, QuantumType magenta, QuantumType yellow, Qu
119119
/// For example: #F000, #FF000000, #FFFF000000000000.</param>
120120
public MagickColor(string color)
121121
{
122-
Throw.IfNullOrEmpty(nameof(color), color);
122+
Throw.IfNullOrEmpty(color);
123123

124124
if (color.Equals("transparent", StringComparison.OrdinalIgnoreCase))
125125
{
@@ -134,7 +134,7 @@ public MagickColor(string color)
134134
}
135135

136136
using var instance = NativeMagickColor.Create();
137-
Throw.IfFalse(nameof(color), instance.Initialize(color), "Invalid color specified");
137+
Throw.IfFalse(instance.Initialize(color), nameof(color), "Invalid color specified");
138138
Initialize(instance);
139139
}
140140

src/Magick.NET/Defines/MagickDefine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ public MagickDefine(MagickFormat format, string name, long value)
111111
/// <param name="value">The value of the define.</param>
112112
public MagickDefine(MagickFormat format, string name, string value)
113113
{
114-
Throw.IfNullOrEmpty(nameof(name), name);
115-
Throw.IfNullOrEmpty(nameof(value), value);
114+
Throw.IfNullOrEmpty(name);
115+
Throw.IfNullOrEmpty(value);
116116

117117
Format = format;
118118
Name = name;

src/Magick.NET/Drawing/Coordinates/DrawableCoordinates.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal abstract class DrawableCoordinates<TCoordinateType> : IReadOnlyList<TCo
1313

1414
protected DrawableCoordinates(IEnumerable<TCoordinateType> coordinates, int minCount)
1515
{
16-
Throw.IfNull(nameof(coordinates), coordinates);
16+
Throw.IfNull(coordinates);
1717

1818
_coordinates = DrawableCoordinates<TCoordinateType>.CheckCoordinates(new List<TCoordinateType>(coordinates), minCount);
1919
}

src/Magick.NET/Drawing/DrawableBorderColor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public sealed partial class DrawableBorderColor : IDrawableBorderColor<QuantumTy
2424
/// <param name="color">The color of the border.</param>
2525
public DrawableBorderColor(IMagickColor<QuantumType> color)
2626
{
27-
Throw.IfNull(nameof(color), color);
27+
Throw.IfNull(color);
2828

2929
Color = color;
3030
}

src/Magick.NET/Drawing/DrawableClipPath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public sealed class DrawableClipPath : IDrawableClipPath, IDrawingWand
1515
/// <param name="clipPath">The ID of the clip path.</param>
1616
public DrawableClipPath(string clipPath)
1717
{
18-
Throw.IfNullOrEmpty(nameof(clipPath), clipPath);
18+
Throw.IfNullOrEmpty(clipPath);
1919

2020
ClipPath = clipPath;
2121
}

src/Magick.NET/Drawing/DrawableComposite.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public DrawableComposite(double x, double y, double width, double height, Compos
5656

5757
private DrawableComposite(IMagickImage<QuantumType> image)
5858
{
59-
Throw.IfNull(nameof(image), image);
59+
Throw.IfNull(image);
6060

6161
Image = image;
6262
}

src/Magick.NET/Drawing/DrawableFillColor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public sealed partial class DrawableFillColor : IDrawableFillColor<QuantumType>,
2424
/// <param name="color">The color to use.</param>
2525
public DrawableFillColor(IMagickColor<QuantumType> color)
2626
{
27-
Throw.IfNull(nameof(color), color);
27+
Throw.IfNull(color);
2828

2929
Color = color;
3030
}

src/Magick.NET/Drawing/DrawableFont.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public DrawableFont(string family)
3030
/// <param name="stretch">The font stretching type.</param>
3131
public DrawableFont(string family, FontStyleType style, FontWeight weight, FontStretch stretch)
3232
{
33-
Throw.IfNullOrEmpty(nameof(family), family);
33+
Throw.IfNullOrEmpty(family);
3434

3535
Family = family;
3636
Style = style;

src/Magick.NET/Drawing/DrawableStrokeColor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public sealed partial class DrawableStrokeColor : IDrawableStrokeColor<QuantumTy
2424
/// <param name="color">The color to use.</param>
2525
public DrawableStrokeColor(IMagickColor<QuantumType> color)
2626
{
27-
Throw.IfNull(nameof(color), color);
27+
Throw.IfNull(color);
2828

2929
Color = color;
3030
}

src/Magick.NET/Drawing/DrawableText.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public sealed class DrawableText : IDrawableText, IDrawingWand
1616
/// <param name="value">The text to draw.</param>
1717
public DrawableText(double x, double y, string value)
1818
{
19-
Throw.IfNullOrEmpty(nameof(value), value);
19+
Throw.IfNullOrEmpty(value);
2020

2121
X = x;
2222
Y = y;

0 commit comments

Comments
 (0)