Skip to content

Modernized some argument checks that still used string literals for parameter names #6766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Microsoft.ML.Core/ComponentModel/ComponentCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal static AccessModifier Accessmodifier(this MethodInfo methodInfo)
return AccessModifier.Internal;
if (methodInfo.IsPublic)
return AccessModifier.Public;
throw new ArgumentException("Did not find access modifier", "methodInfo");
throw new ArgumentException("Did not find access modifier", nameof(methodInfo));
}

internal static AccessModifier Accessmodifier(this ConstructorInfo constructorInfo)
Expand All @@ -47,7 +47,7 @@ internal static AccessModifier Accessmodifier(this ConstructorInfo constructorIn
return AccessModifier.Internal;
if (constructorInfo.IsPublic)
return AccessModifier.Public;
throw new ArgumentException("Did not find access modifier", "constructorInfo");
throw new ArgumentException("Did not find access modifier", nameof(constructorInfo));
}

internal enum AccessModifier
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.ML.TorchSharp/Utils/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Index(int value, bool fromEnd = false)
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("value", "Non-negative number required.");
throw new ArgumentOutOfRangeException(nameof(value), "Non-negative number required.");
}

if (fromEnd)
Expand Down Expand Up @@ -57,7 +57,7 @@ public static Index FromStart(int value)
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("value", "Non-negative number required.");
throw new ArgumentOutOfRangeException(nameof(value), "Non-negative number required.");
}

return new Index(value);
Expand All @@ -70,7 +70,7 @@ public static Index FromEnd(int value)
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("value", "Non-negative number required.");
throw new ArgumentOutOfRangeException(nameof(value), "Non-negative number required.");
}

return new Index(~value);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.TorchSharp/Utils/Range.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public override string ToString()

if ((uint)end > (uint)length || (uint)start > (uint)end)
{
throw new ArgumentOutOfRangeException("length");
throw new ArgumentOutOfRangeException(nameof(length));
}

return (start, end - start);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static IEnumerable<TypeTestData> GenerateDataset(int numExamples = 5, int
public static TypeTestData GetRandomInstance(Random rng)
{
if (rng == null)
throw new ArgumentNullException("rng");
throw new ArgumentNullException(nameof(rng));

return new TypeTestData
{
Expand Down