Skip to content

Commit 609d638

Browse files
author
Luca Piccioni
committed
Use nameof in ArgumentNullException/ArgumentException usages.
1 parent c6f0a79 commit 609d638

85 files changed

Lines changed: 589 additions & 589 deletions

File tree

Some content is hidden

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

OpenGL.Net.CoreUI/NativeWindowEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class NativeWindowEventArgs : EventArgs
4242
internal NativeWindowEventArgs(DeviceContext deviceContext, IntPtr renderContext)
4343
{
4444
if (deviceContext == null)
45-
throw new ArgumentNullException("deviceContext");
45+
throw new ArgumentNullException(nameof(deviceContext));
4646
if (renderContext == IntPtr.Zero)
4747
throw new ArgumentException("renderContext");
4848

OpenGL.Net.Objects/AlignedMemoryBuffer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public class AlignedMemoryBuffer : IDisposable
5252
public AlignedMemoryBuffer(uint size, uint alignment)
5353
{
5454
if (size == 0)
55-
throw new ArgumentException("invalid", "size");
55+
throw new ArgumentException("invalid", nameof(size));
5656
if ((alignment != 0) && (alignment != 4) && (alignment != 8) && (alignment != 16) && (alignment != 32))
57-
throw new ArgumentException("invalid", "alignment");
57+
throw new ArgumentException("invalid", nameof(alignment));
5858

5959
// Store alignment
6060
_Alignment = alignment;
@@ -177,9 +177,9 @@ public void CopyBuffer(AlignedMemoryBuffer otherMemoryBuffer, ulong otherOffset,
177177
if (IsDisposed)
178178
throw new ObjectDisposedException("AlignedMemoryBuffer");
179179
if (otherMemoryBuffer == null)
180-
throw new ArgumentNullException("otherMemoryBuffer");
180+
throw new ArgumentNullException(nameof(otherMemoryBuffer));
181181
if (otherMemoryBuffer._UnmanagedBuffer == IntPtr.Zero)
182-
throw new ArgumentException("disposed", "otherMemoryBuffer");
182+
throw new ArgumentException("disposed", nameof(otherMemoryBuffer));
183183
if (thisOffset + bytesCopied >= otherMemoryBuffer.Size - otherOffset)
184184
throw new InvalidOperationException("copying out of bounds");
185185

OpenGL.Net.Objects/ArrayBuffer.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public T[] ToArray<T>(uint arrayLength) where T : struct
219219
// Array element item size cannot exceed ItemSize
220220
uint arrayItemSize = arrayElementVertexType.GetItemSize();
221221
if (arrayItemSize > ItemSize)
222-
throw new ArgumentException("array element type too big", "array");
222+
throw new InvalidOperationException("array element type too big");
223223

224224
T[] array = new T[arrayLength];
225225

@@ -378,13 +378,13 @@ public static ArrayBuffer CreateArrayObject(ArrayBufferItemType vertexArrayType,
378378
public void Copy(ArrayBuffer buffer, uint[] indices, uint count, uint offset, uint stride)
379379
{
380380
if (buffer == null)
381-
throw new ArgumentNullException("buffer");
381+
throw new ArgumentNullException(nameof(buffer));
382382
if (indices == null)
383-
throw new ArgumentNullException("indices");
383+
throw new ArgumentNullException(nameof(indices));
384384
if (count == 0)
385-
throw new ArgumentException("invalid", "count");
385+
throw new ArgumentException("invalid", nameof(count));
386386
if (stride == 0)
387-
throw new ArgumentException("invalid", "stride");
387+
throw new ArgumentException("invalid", nameof(stride));
388388
if (offset + ((count - 1) * stride) > indices.Length)
389389
throw new InvalidOperationException("indices out of bounds");
390390
if (_ArrayType.GetVertexBaseType() != buffer._ArrayType.GetVertexBaseType())
@@ -444,13 +444,13 @@ public void Copy(ArrayBuffer buffer, uint[] indices, uint count, uint offset, ui
444444
public void Copy(ArrayBuffer buffer, uint[] indices, uint[] vcount, uint offset, uint stride)
445445
{
446446
if (buffer == null)
447-
throw new ArgumentNullException("buffer");
447+
throw new ArgumentNullException(nameof(buffer));
448448
if (indices == null)
449-
throw new ArgumentNullException("indices");
449+
throw new ArgumentNullException(nameof(indices));
450450
if (vcount == null)
451-
throw new ArgumentNullException("indices");
451+
throw new ArgumentNullException(nameof(indices));
452452
if (stride == 0)
453-
throw new ArgumentException("invalid", "stride");
453+
throw new ArgumentException("invalid", nameof(stride));
454454
if (_ArrayType.GetVertexBaseType() != buffer._ArrayType.GetVertexBaseType())
455455
throw new InvalidOperationException("base type mismatch");
456456

@@ -463,7 +463,7 @@ public void Copy(ArrayBuffer buffer, uint[] indices, uint[] vcount, uint offset,
463463
});
464464

465465
if ((minVertices < 3) && (maxVertices >= 3))
466-
throw new ArgumentException("ambigous polygons set", "vcount");
466+
throw new ArgumentException("ambigous polygons set", nameof(vcount));
467467

468468
uint totalVerticesCount = 0;
469469

@@ -624,7 +624,7 @@ public ArrayBuffer<T> ConvertItemType<T>() where T : struct
624624
public ArrayBuffer ConvertItemType(ArrayBufferItemType vertexArrayType)
625625
{
626626
if (_ArrayType.GetVertexBaseType() != vertexArrayType.GetVertexBaseType())
627-
throw new ArgumentException("base type mismatch", "vertexArrayType");
627+
throw new ArgumentException("base type mismatch", nameof(vertexArrayType));
628628

629629
uint componentsCount = CpuItemsCount * ArrayType.GetArrayLength() * ArrayType.GetArrayRank();
630630
uint convComponentsCount = vertexArrayType.GetArrayLength() * vertexArrayType.GetArrayRank();

OpenGL.Net.Objects/ArrayBufferBase.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ protected internal interface IArraySection
310310
public virtual void Create(uint itemsCount)
311311
{
312312
if (itemsCount == 0)
313-
throw new ArgumentException("invalid", "itemsCount");
313+
throw new ArgumentException("invalid", nameof(itemsCount));
314314

315315
// Allocate buffer
316316
CreateCpuBuffer(itemsCount * ItemSize);
@@ -342,7 +342,7 @@ public virtual void Create(GraphicsContext ctx, uint itemsCount)
342342
CheckCurrentContext(ctx);
343343

344344
if (itemsCount == 0)
345-
throw new ArgumentException("invalid", "itemsCount");
345+
throw new ArgumentException("invalid", nameof(itemsCount));
346346

347347
// Object already existing: resize client buffer, if any
348348
if (CpuBufferAddress != IntPtr.Zero)
@@ -389,7 +389,7 @@ public virtual void Create(GraphicsContext ctx, uint itemsCount)
389389
public virtual void Create(Array array, uint offset, uint count)
390390
{
391391
if (count == 0)
392-
throw new ArgumentException("zero not allowed", "count");
392+
throw new ArgumentException("zero not allowed", nameof(count));
393393

394394
// Array element item size cannot exceed ItemSize
395395
uint arrayItemSize = CheckArrayItemSize(array);
@@ -503,7 +503,7 @@ public virtual void Create(GraphicsContext ctx, Array array, uint offset, uint c
503503
CheckCurrentContext(ctx);
504504

505505
if (count == 0)
506-
throw new ArgumentException("zero not allowed", "count");
506+
throw new ArgumentException("zero not allowed", nameof(count));
507507

508508
// Array element item size cannot exceed ItemSize
509509
uint arrayItemSize = CheckArrayItemSize(array);
@@ -637,18 +637,18 @@ protected virtual void CopyBuffer(IntPtr buffer, Array array, uint arrayItemSize
637637
private uint CheckArrayItemSize(Array array)
638638
{
639639
if (array == null)
640-
throw new ArgumentNullException("array");
640+
throw new ArgumentNullException(nameof(array));
641641
if (array.Rank != 1)
642642
throw new ArgumentException(String.Format("copying from array of rank {0} not supported", array.Rank));
643643

644644
Type arrayElementType = array.GetType().GetElementType();
645645
if (arrayElementType == null || !arrayElementType.IsValueType)
646-
throw new ArgumentException("invalid array element type", "array");
646+
throw new ArgumentException("invalid array element type", nameof(array));
647647

648648
// Array element item size cannot exceed ItemSize
649649
uint arrayItemSize = (uint)Marshal.SizeOf(arrayElementType);
650650
if (arrayItemSize > ItemSize)
651-
throw new ArgumentException("array element type too big", "array");
651+
throw new ArgumentException("array element type too big", nameof(array));
652652

653653
return (arrayItemSize);
654654
}
@@ -691,7 +691,7 @@ public virtual void Update(GraphicsContext ctx, Array array, uint offset, uint c
691691
CheckThisExistence(ctx);
692692

693693
if (count == 0)
694-
throw new ArgumentException("zero not allowed", "count");
694+
throw new ArgumentException("zero not allowed", nameof(count));
695695
if (IsMapped)
696696
throw new InvalidOperationException("mapped");
697697

@@ -879,15 +879,15 @@ protected static void CopyArray(
879879
uint srcIndex, uint srcCount)
880880
{
881881
if (dst == IntPtr.Zero)
882-
throw new ArgumentException("invalid pointer", "dst");
882+
throw new ArgumentException("invalid pointer", nameof(dst));
883883
if (src == null)
884-
throw new ArgumentNullException("src");
884+
throw new ArgumentNullException(nameof(src));
885885
if (srcItemSize > dstItemSize)
886-
throw new ArgumentException("too large", "srcItemSize");
886+
throw new ArgumentException("too large", nameof(srcItemSize));
887887
if (src.Length < srcCount)
888-
throw new ArgumentException("exceed array length", "srcCount");
888+
throw new ArgumentException("exceed array length", nameof(srcCount));
889889
if (src.Length < srcIndex + srcCount)
890-
throw new ArgumentException("exceed array length", "srcOffset");
890+
throw new ArgumentException("exceed array length", nameof(srcOffset));
891891

892892
if (srcStride == IntPtr.Zero)
893893
srcStride = new IntPtr(srcItemSize);
@@ -1026,15 +1026,15 @@ protected static void CopyArray(
10261026
uint dstIndex, uint dstCount)
10271027
{
10281028
if (dst == null)
1029-
throw new ArgumentNullException("dst");
1029+
throw new ArgumentNullException(nameof(dst));
10301030
if (src == IntPtr.Zero)
1031-
throw new ArgumentException("invalid pointer", "src");
1031+
throw new ArgumentException("invalid pointer", nameof(src));
10321032
if (srcItemSize > dstItemSize)
1033-
throw new ArgumentException("too large", "dstItemSize");
1033+
throw new ArgumentException("too large", nameof(dstItemSize));
10341034
if (dst.Length < dstCount)
1035-
throw new ArgumentException("exceed array length", "dstCount");
1035+
throw new ArgumentException("exceed array length", nameof(dstCount));
10361036
if (dst.Length < dstIndex + dstCount)
1037-
throw new ArgumentException("exceed array length", "dstOffset");
1037+
throw new ArgumentException("exceed array length", nameof(dstOffset));
10381038

10391039
if (srcStride == IntPtr.Zero)
10401040
srcStride = new IntPtr(srcItemSize);

OpenGL.Net.Objects/ArrayBufferItem.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public ArrayBufferItem(ArrayBufferItemType vertexArrayType)
9898
public ArrayBufferItem(ArrayBufferItemAttribute attribute)
9999
{
100100
if (attribute == null)
101-
throw new ArgumentNullException("attribute");
101+
throw new ArgumentNullException(nameof(attribute));
102102

103103
ArrayType = attribute.ArrayBaseType.GetArrayBufferType(attribute.ArrayLength, attribute.ArrayRank);
104104
}
@@ -167,7 +167,7 @@ public bool Normalized
167167
public static bool IsDataSupported(GraphicsContext ctx, VertexBaseType baseType)
168168
{
169169
if (ctx == null)
170-
throw new ArgumentNullException("ctx");
170+
throw new ArgumentNullException(nameof(ctx));
171171

172172
switch (baseType) {
173173
case VertexBaseType.Half:
@@ -211,7 +211,7 @@ public static bool IsDataSupported(GraphicsContext ctx, ArrayBufferItemType arra
211211
public static ArrayBufferItemType GetArrayType(Type type)
212212
{
213213
if (type == null)
214-
throw new ArgumentNullException("type");
214+
throw new ArgumentNullException(nameof(type));
215215

216216
// Support .NET Framework types
217217
// Support OpenGL.Net.Math types
@@ -310,7 +310,7 @@ public static ArrayBufferItemType GetArrayType(Type type)
310310
return (attribute.ArrayType);
311311
}
312312

313-
throw new ArgumentException("not corresponding information", "type");
313+
throw new ArgumentException("not corresponding information", nameof(type));
314314
}
315315

316316
/// <summary>
@@ -321,7 +321,7 @@ public static ArrayBufferItemType GetArrayType(Type type)
321321
public static VertexBaseType GetArrayBaseType(Type type)
322322
{
323323
if (type == null)
324-
throw new ArgumentNullException("type");
324+
throw new ArgumentNullException(nameof(type));
325325

326326
if (type == typeof(Single))
327327
return (VertexBaseType.Float);

OpenGL.Net.Objects/CoreImageCodecPlugin.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ public ImageInfo QueryInfo(string path, ImageCodecCriteria criteria)
470470
public ImageInfo QueryInfo(Stream stream, ImageCodecCriteria criteria)
471471
{
472472
if (stream == null)
473-
throw new ArgumentNullException("stream");
473+
throw new ArgumentNullException(nameof(stream));
474474
if (criteria == null)
475-
throw new ArgumentNullException("criteria");
475+
throw new ArgumentNullException(nameof(criteria));
476476

477477
ImageInfo info = new ImageInfo();
478478

@@ -532,9 +532,9 @@ public Image Load(string path, ImageCodecCriteria criteria)
532532
public Image Load(Stream stream, ImageCodecCriteria criteria)
533533
{
534534
if (stream == null)
535-
throw new ArgumentNullException("stream");
535+
throw new ArgumentNullException(nameof(stream));
536536
if (criteria == null)
537-
throw new ArgumentNullException("criteria");
537+
throw new ArgumentNullException(nameof(criteria));
538538

539539
using (System.Drawing.Bitmap iBitmap = new System.Drawing.Bitmap(stream)) {
540540
Image image;
@@ -598,9 +598,9 @@ public Image Load(Stream stream, ImageCodecCriteria criteria)
598598
internal static Image LoadFromBitmap(Bitmap bitmap, ImageCodecCriteria criteria)
599599
{
600600
if (bitmap == null)
601-
throw new ArgumentNullException("bitmap");
601+
throw new ArgumentNullException(nameof(bitmap));
602602
if (criteria == null)
603-
throw new ArgumentNullException("criteria");
603+
throw new ArgumentNullException(nameof(criteria));
604604

605605
PixelLayout pType, pConvType;
606606

@@ -661,9 +661,9 @@ internal static Image LoadFromBitmap(Bitmap bitmap, ImageCodecCriteria criteria)
661661
private static void LoadBitmapByLockBits(Bitmap bitmap, Image image)
662662
{
663663
if (bitmap == null)
664-
throw new ArgumentNullException("bitmap");
664+
throw new ArgumentNullException(nameof(bitmap));
665665
if (image == null)
666-
throw new ArgumentNullException("image");
666+
throw new ArgumentNullException(nameof(image));
667667

668668
System.Drawing.Imaging.BitmapData iBitmapData = null;
669669
IntPtr imageData = image.ImageBuffer;
@@ -720,9 +720,9 @@ private static void LoadBitmapByLockBits(Bitmap bitmap, Image image)
720720
private static void LoadBitmapByPixel(Bitmap bitmap, Image image)
721721
{
722722
if (bitmap == null)
723-
throw new ArgumentNullException("bitmap");
723+
throw new ArgumentNullException(nameof(bitmap));
724724
if (image == null)
725-
throw new ArgumentNullException("image");
725+
throw new ArgumentNullException(nameof(image));
726726

727727
// FIXME Maybe this method is no more necessary
728728
throw new NotImplementedException();
@@ -763,9 +763,9 @@ private static void LoadBitmapByPixel(Bitmap bitmap, Image image)
763763
private static void LoadBitmapByClone(Bitmap bitmap, Image image)
764764
{
765765
if (bitmap == null)
766-
throw new ArgumentNullException("bitmap");
766+
throw new ArgumentNullException(nameof(bitmap));
767767
if (image == null)
768-
throw new ArgumentNullException("image");
768+
throw new ArgumentNullException(nameof(image));
769769

770770
System.Drawing.Imaging.PixelFormat iBitmapFormat;
771771
int iBitmapFlags;

OpenGL.Net.Objects/ElementBuffer.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public ElementBuffer(DrawElementsType elementType, BufferUsage hint) :
6161
RestartIndexKey = 0xFFFFFFFF;
6262
break;
6363
default:
64-
throw new ArgumentException("type not supported", "elementType");
64+
throw new ArgumentException("type not supported", nameof(elementType));
6565
}
6666
} catch {
6767
// Avoid finalizer assertion failure (don't call dispose since it's virtual)
@@ -99,7 +99,7 @@ public ElementBuffer(DrawElementsType elementType, BufferStorageMask usageMask)
9999
RestartIndexKey = 0xFFFFFFFF;
100100
break;
101101
default:
102-
throw new ArgumentException("type not supported", "elementType");
102+
throw new ArgumentException("type not supported", nameof(elementType));
103103
}
104104
} catch {
105105
// Avoid finalizer assertion failure (don't call dispose since it's virtual)
@@ -140,7 +140,7 @@ public ElementBuffer(DrawElementsType elementType, BufferUsage hint, BufferStora
140140
RestartIndexKey = 0xFFFFFFFF;
141141
break;
142142
default:
143-
throw new ArgumentException("type not supported", "elementType");
143+
throw new ArgumentException("type not supported", nameof(elementType));
144144
}
145145
} catch {
146146
// Avoid finalizer assertion failure (don't call dispose since it's virtual)
@@ -180,7 +180,7 @@ protected ElementBuffer(Type elementType, BufferUsage hint) :
180180
RestartIndexKey = 0xFFFFFFFF;
181181
break;
182182
default:
183-
throw new ArgumentException("type not supported", "elementType");
183+
throw new ArgumentException("type not supported", nameof(elementType));
184184
}
185185
} catch {
186186
// Avoid finalizer assertion failure (don't call dispose since it's virtual)
@@ -220,7 +220,7 @@ protected ElementBuffer(Type elementType, BufferStorageMask usageMask) :
220220
RestartIndexKey = 0xFFFFFFFF;
221221
break;
222222
default:
223-
throw new ArgumentException("type not supported", "elementType");
223+
throw new ArgumentException("type not supported", nameof(elementType));
224224
}
225225
} catch {
226226
// Avoid finalizer assertion failure (don't call dispose since it's virtual)
@@ -263,7 +263,7 @@ protected ElementBuffer(Type elementType, BufferUsage hint, BufferStorageMask us
263263
RestartIndexKey = 0xFFFFFFFF;
264264
break;
265265
default:
266-
throw new ArgumentException("type not supported", "elementType");
266+
throw new ArgumentException("type not supported", nameof(elementType));
267267
}
268268
} catch {
269269
// Avoid finalizer assertion failure (don't call dispose since it's virtual)
@@ -685,7 +685,7 @@ public static uint DefaultRestartIndex
685685
case TypeCode.UInt32:
686686
return (0xFFFFFFFF);
687687
default:
688-
throw new ArgumentException("type not supported", "elementType");
688+
throw new InvalidOperationException("type not supported");
689689
}
690690
}
691691
}

0 commit comments

Comments
 (0)