Skip to content

Commit 077a6b8

Browse files
LehontiJohn Doe
and
John Doe
authored
Modernized some argument checks that still used string literals for parameter names (#6766)
Co-authored-by: John Doe <john@doe>
1 parent ea84d42 commit 077a6b8

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

src/Microsoft.ML.Core/ComponentModel/ComponentCatalog.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal static AccessModifier Accessmodifier(this MethodInfo methodInfo)
3030
return AccessModifier.Internal;
3131
if (methodInfo.IsPublic)
3232
return AccessModifier.Public;
33-
throw new ArgumentException("Did not find access modifier", "methodInfo");
33+
throw new ArgumentException("Did not find access modifier", nameof(methodInfo));
3434
}
3535

3636
internal static AccessModifier Accessmodifier(this ConstructorInfo constructorInfo)
@@ -47,7 +47,7 @@ internal static AccessModifier Accessmodifier(this ConstructorInfo constructorIn
4747
return AccessModifier.Internal;
4848
if (constructorInfo.IsPublic)
4949
return AccessModifier.Public;
50-
throw new ArgumentException("Did not find access modifier", "constructorInfo");
50+
throw new ArgumentException("Did not find access modifier", nameof(constructorInfo));
5151
}
5252

5353
internal enum AccessModifier

src/Microsoft.ML.TorchSharp/Utils/Index.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public Index(int value, bool fromEnd = false)
2929
{
3030
if (value < 0)
3131
{
32-
throw new ArgumentOutOfRangeException("value", "Non-negative number required.");
32+
throw new ArgumentOutOfRangeException(nameof(value), "Non-negative number required.");
3333
}
3434

3535
if (fromEnd)
@@ -57,7 +57,7 @@ public static Index FromStart(int value)
5757
{
5858
if (value < 0)
5959
{
60-
throw new ArgumentOutOfRangeException("value", "Non-negative number required.");
60+
throw new ArgumentOutOfRangeException(nameof(value), "Non-negative number required.");
6161
}
6262

6363
return new Index(value);
@@ -70,7 +70,7 @@ public static Index FromEnd(int value)
7070
{
7171
if (value < 0)
7272
{
73-
throw new ArgumentOutOfRangeException("value", "Non-negative number required.");
73+
throw new ArgumentOutOfRangeException(nameof(value), "Non-negative number required.");
7474
}
7575

7676
return new Index(~value);

src/Microsoft.ML.TorchSharp/Utils/Range.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public override string ToString()
125125

126126
if ((uint)end > (uint)length || (uint)start > (uint)end)
127127
{
128-
throw new ArgumentOutOfRangeException("length");
128+
throw new ArgumentOutOfRangeException(nameof(length));
129129
}
130130

131131
return (start, end - start);

test/Microsoft.ML.IntegrationTests/Datasets/TypeTestData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public static IEnumerable<TypeTestData> GenerateDataset(int numExamples = 5, int
123123
public static TypeTestData GetRandomInstance(Random rng)
124124
{
125125
if (rng == null)
126-
throw new ArgumentNullException("rng");
126+
throw new ArgumentNullException(nameof(rng));
127127

128128
return new TypeTestData
129129
{

0 commit comments

Comments
 (0)