diff --git a/ShareX.HelpersLib/Controls/BlackStyle/BlackStyleProgressBar.cs b/ShareX.HelpersLib/Controls/BlackStyle/BlackStyleProgressBar.cs index c1ac9caf7..6592f8b05 100644 --- a/ShareX.HelpersLib/Controls/BlackStyle/BlackStyleProgressBar.cs +++ b/ShareX.HelpersLib/Controls/BlackStyle/BlackStyleProgressBar.cs @@ -46,7 +46,7 @@ public int Minimum { if (value < 0) { - throw new ArgumentOutOfRangeException("Minimum"); + throw new ArgumentOutOfRangeException(nameof(Minimum)); } if (maximum < value) @@ -81,7 +81,7 @@ public int Maximum { if (value < 0) { - throw new ArgumentOutOfRangeException("Maximum"); + throw new ArgumentOutOfRangeException(nameof(Maximum)); } if (minimum > value) @@ -114,9 +114,9 @@ public int Value { if (this.value != value) { - if ((value < minimum) || (value > maximum)) + if (value < minimum || value > maximum) { - throw new ArgumentOutOfRangeException("Value"); + throw new ArgumentOutOfRangeException(nameof(Value)); } this.value = value; diff --git a/ShareX.HelpersLib/Extensions/Extensions.cs b/ShareX.HelpersLib/Extensions/Extensions.cs index 18c063acf..d4041b833 100644 --- a/ShareX.HelpersLib/Extensions/Extensions.cs +++ b/ShareX.HelpersLib/Extensions/Extensions.cs @@ -44,8 +44,8 @@ public static class Extensions { public static void ForEach(this IEnumerable source, Action action) { - if (source == null) throw new ArgumentNullException("source"); - if (action == null) throw new ArgumentNullException("action"); + if (source == null) throw new ArgumentNullException(nameof(source)); + if (action == null) throw new ArgumentNullException(nameof(action)); foreach (T item in source) { diff --git a/ShareX.HelpersLib/Random/RandomCrypto.cs b/ShareX.HelpersLib/Random/RandomCrypto.cs index e7888658c..81e663b8f 100644 --- a/ShareX.HelpersLib/Random/RandomCrypto.cs +++ b/ShareX.HelpersLib/Random/RandomCrypto.cs @@ -53,7 +53,7 @@ public static int Next(int maxValue) { if (maxValue < 0) { - throw new ArgumentOutOfRangeException("maxValue"); + throw new ArgumentOutOfRangeException(nameof(maxValue)); } return Next(0, maxValue); @@ -69,7 +69,7 @@ public static int Next(int minValue, int maxValue) if (minValue > maxValue) { - throw new ArgumentOutOfRangeException("minValue"); + throw new ArgumentOutOfRangeException(nameof(minValue)); } if (minValue == maxValue) @@ -115,7 +115,7 @@ public static void NextBytes(byte[] buffer) { if (buffer == null) { - throw new ArgumentNullException("buffer"); + throw new ArgumentNullException(nameof(buffer)); } lock (randomLock) @@ -126,7 +126,22 @@ public static void NextBytes(byte[] buffer) public static T Pick(params T[] array) { + if (array == null) + { + throw new ArgumentNullException(nameof(array)); + } + + if (array.Length == 0) + { + throw new ArgumentException(nameof(array)); + } + return array[Next(array.Length - 1)]; } + + public static void Run(params Action[] actions) + { + Pick(actions)(); + } } } \ No newline at end of file diff --git a/ShareX.HelpersLib/Random/RandomFast.cs b/ShareX.HelpersLib/Random/RandomFast.cs index f60e7c0eb..24db6baf1 100644 --- a/ShareX.HelpersLib/Random/RandomFast.cs +++ b/ShareX.HelpersLib/Random/RandomFast.cs @@ -47,6 +47,11 @@ public static int Next() /// A 32-bit signed integer that is greater than or equal to 0 and less than or equal to . public static int Next(int maxValue) { + if (maxValue < 0) + { + throw new ArgumentOutOfRangeException(nameof(maxValue)); + } + lock (randomLock) { return random.Next(maxValue + 1); @@ -59,6 +64,16 @@ public static int Next(int maxValue) /// A 32-bit signed integer that is greater than or equal to and less than or equal to . public static int Next(int minValue, int maxValue) { + if (minValue > maxValue) + { + throw new ArgumentOutOfRangeException(nameof(minValue)); + } + + if (minValue == maxValue) + { + return minValue; + } + lock (randomLock) { return random.Next(minValue, maxValue + 1); @@ -79,6 +94,11 @@ public static double NextDouble() /// An array of bytes to contain random numbers. public static void NextBytes(byte[] buffer) { + if (buffer == null) + { + throw new ArgumentNullException(nameof(buffer)); + } + lock (randomLock) { random.NextBytes(buffer); @@ -87,7 +107,22 @@ public static void NextBytes(byte[] buffer) public static T Pick(params T[] array) { + if (array == null) + { + throw new ArgumentNullException(nameof(array)); + } + + if (array.Length == 0) + { + throw new ArgumentException(nameof(array)); + } + return array[Next(array.Length - 1)]; } + + public static void Run(params Action[] actions) + { + Pick(actions)(); + } } } \ No newline at end of file diff --git a/ShareX.UploadersLib/Forms/JiraUpload.cs b/ShareX.UploadersLib/Forms/JiraUpload.cs index 98612305d..d41be2e58 100644 --- a/ShareX.UploadersLib/Forms/JiraUpload.cs +++ b/ShareX.UploadersLib/Forms/JiraUpload.cs @@ -56,7 +56,7 @@ public JiraUpload(string issuePrefix, GetSummaryHandler getSummary) : this() { if (getSummary == null) { - throw new ArgumentNullException("getSummary"); + throw new ArgumentNullException(nameof(getSummary)); } this.issuePrefix = issuePrefix; this.getSummary = getSummary;