Skip to content

Commit ff8218a

Browse files
radekdoulikjonpryor
authored andcommitted
[Java.Intreop] Use newer language features and fix a typo (#242)
1 parent 62815a9 commit ff8218a

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/Java.Interop/Java.Interop/JavaArray.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,38 @@ public virtual IEnumerator<T> GetEnumerator ()
6262
internal static void CheckArrayCopy (int sourceIndex, int sourceLength, int destinationIndex, int destinationLength, int length)
6363
{
6464
if (sourceIndex < 0)
65-
throw new ArgumentOutOfRangeException ("sourceIndex", $"source index must be >= 0; was {sourceIndex}.");
65+
throw new ArgumentOutOfRangeException (nameof (sourceIndex), $"source index must be >= 0; was {sourceIndex}.");
6666
if (sourceIndex != 0 && sourceIndex >= sourceLength)
67-
throw new ArgumentException ("source index is > source length.", "sourceIndex");
67+
throw new ArgumentException ("source index is > source length.", nameof (sourceIndex));
6868
if (checked(sourceIndex + length) > sourceLength)
69-
throw new ArgumentException ("source index + length >= source length", "length");
69+
throw new ArgumentException ("source index + length >= source length", nameof (length));
7070
if (destinationIndex < 0)
71-
throw new ArgumentOutOfRangeException ("destinationIndex", $"destination index must be >= 0; was {destinationIndex}.");
71+
throw new ArgumentOutOfRangeException (nameof (destinationIndex), $"destination index must be >= 0; was {destinationIndex}.");
7272
if (destinationIndex != 0 && destinationIndex >= destinationLength)
73-
throw new ArgumentException ("destination index is > destination length.", "destinationIndex");
73+
throw new ArgumentException ("destination index is > destination length.", nameof (destinationIndex));
7474
if (checked (destinationIndex + length) > destinationLength)
75-
throw new ArgumentException ("destination index + length >= destination length", "length");
75+
throw new ArgumentException ("destination index + length >= destination length", nameof (length));
7676
}
7777

7878
internal static int CheckLength (int length)
7979
{
8080
if (length < 0)
81-
throw new ArgumentException ("'length' cannot be negative.", "length");
81+
throw new ArgumentException ("'length' cannot be negative.", nameof (length));
8282
return length;
8383
}
8484

8585
internal static int CheckLength (IList<T> value)
8686
{
8787
if (value == null)
88-
throw new ArgumentNullException ("value");
88+
throw new ArgumentNullException (nameof (value));
8989
return value.Count;
9090
}
9191

9292
internal static IList<T> ToList (IEnumerable<T> value)
9393
{
9494
if (value == null)
95-
throw new ArgumentNullException ("value");
96-
IList<T> list = value as IList<T>;
97-
if (list != null)
95+
throw new ArgumentNullException (nameof (value));
96+
if (value is IList<T> list)
9897
return list;
9998
return value.ToList ();
10099
}
@@ -138,8 +137,7 @@ internal static JniValueMarshalerState CreateArgumentState<TArray> (IList<T
138137
{
139138
if (value == null)
140139
return new JniValueMarshalerState ();
141-
var v = value as TArray;
142-
if (v != null) {
140+
if (value is TArray v) {
143141
return new JniValueMarshalerState (v);
144142
}
145143
var list = value as IList<T>;
@@ -227,7 +225,7 @@ object IList.this [int index] {
227225
void ICollection.CopyTo (Array array, int index)
228226
{
229227
if (array == null)
230-
throw new ArgumentNullException ("array");
228+
throw new ArgumentNullException (nameof (array));
231229
CheckArrayCopy (0, Length, index, array.Length, Length);
232230
int len = Length;
233231
for (int i = 0; i < len; i++)
@@ -301,7 +299,7 @@ public abstract class JniArrayElements : IDisposable {
301299
internal JniArrayElements (IntPtr elements)
302300
{
303301
if (elements == IntPtr.Zero)
304-
throw new ArgumentException ("'elements' must not be IntPtr.Zero.", "elements");
302+
throw new ArgumentException ("'elements' must not be IntPtr.Zero.", nameof (elements));
305303
this.elements = elements;
306304
}
307305

@@ -327,7 +325,7 @@ public void CopyToJava ()
327325
public void Release (JniReleaseArrayElementsMode releaseMode)
328326
{
329327
if (IsDisposed)
330-
throw new ObjectDisposedException (GetType ().FullName);;
328+
throw new ObjectDisposedException (GetType ().FullName);
331329
Synchronize (releaseMode);
332330
elements = IntPtr.Zero;
333331
}
@@ -360,7 +358,7 @@ public override T this [int index] {
360358
}
361359
set {
362360
if (index >= Length)
363-
throw new ArgumentOutOfRangeException ("index", "index >= Length");
361+
throw new ArgumentOutOfRangeException (nameof (index), "index >= Length");
364362
var buf = new T []{ value };
365363
CopyFrom (buf, 0, index, buf.Length);
366364
}
@@ -378,8 +376,7 @@ public override void CopyTo (T[] array, int arrayIndex)
378376

379377
internal static T[] ToArray (IEnumerable<T> value)
380378
{
381-
var array = value as T[];
382-
if (array != null)
379+
if (value is T [] array)
383380
return array;
384381
return value.ToArray ();
385382
}

0 commit comments

Comments
 (0)