diff --git a/.editorconfig b/.editorconfig index 81f23aab1..e0abd4f07 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,6 +6,7 @@ root = true [*] charset = utf-8 +#file_header_template = · _ _ _ ____ _ _____\n / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___\n / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \\n / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |\n/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|\n\nCopyright 2015-2021 Łukasz "JustArchi" Domeradzki\nContact: JustArchi@JustArchi.net\n\nLicensed under the Apache License, Version 2.0 (the "License")\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an "AS IS" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License. indent_style = tab insert_final_newline = true trim_trailing_whitespace = true diff --git a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/CatAPI.cs b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/CatAPI.cs index a0ac94261..39988507a 100644 --- a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/CatAPI.cs +++ b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/CatAPI.cs @@ -35,9 +35,7 @@ internal static class CatAPI { private const string URL = "https://aws.random.cat"; internal static async Task GetRandomCatURL(WebBrowser webBrowser) { - if (webBrowser == null) { - throw new ArgumentNullException(nameof(webBrowser)); - } + ArgumentNullException.ThrowIfNull(webBrowser); Uri request = new($"{URL}/meow"); diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs index bac14d3a4..48b2ced9e 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs @@ -141,9 +141,7 @@ internal sealed class GlobalCache : SerializableFile { throw new ArgumentOutOfRangeException(nameof(currentChangeNumber)); } - if (appChanges == null) { - throw new ArgumentNullException(nameof(appChanges)); - } + ArgumentNullException.ThrowIfNull(appChanges); if (currentChangeNumber <= LastChangeNumber) { return; @@ -181,9 +179,7 @@ internal sealed class GlobalCache : SerializableFile { internal bool ShouldRefreshDepotKey(uint depotID) => !DepotKeys.ContainsKey(depotID); internal void UpdateAppChangeNumbers(IReadOnlyCollection> appChangeNumbers) { - if (appChangeNumbers == null) { - throw new ArgumentNullException(nameof(appChangeNumbers)); - } + ArgumentNullException.ThrowIfNull(appChangeNumbers); bool save = false; @@ -202,13 +198,9 @@ internal sealed class GlobalCache : SerializableFile { } internal void UpdateAppTokens(IReadOnlyCollection> appTokens, IReadOnlyCollection publicAppIDs) { - if (appTokens == null) { - throw new ArgumentNullException(nameof(appTokens)); - } + ArgumentNullException.ThrowIfNull(appTokens); - if (publicAppIDs == null) { - throw new ArgumentNullException(nameof(publicAppIDs)); - } + ArgumentNullException.ThrowIfNull(publicAppIDs); bool save = false; @@ -236,9 +228,7 @@ internal sealed class GlobalCache : SerializableFile { } internal void UpdateDepotKeys(ICollection depotKeyResults) { - if (depotKeyResults == null) { - throw new ArgumentNullException(nameof(depotKeyResults)); - } + ArgumentNullException.ThrowIfNull(depotKeyResults); bool save = false; @@ -269,9 +259,7 @@ internal sealed class GlobalCache : SerializableFile { } internal void UpdatePackageTokens(IReadOnlyCollection> packageTokens) { - if (packageTokens == null) { - throw new ArgumentNullException(nameof(packageTokens)); - } + ArgumentNullException.ThrowIfNull(packageTokens); bool save = false; @@ -290,17 +278,11 @@ internal sealed class GlobalCache : SerializableFile { } internal void UpdateSubmittedData(IReadOnlyDictionary apps, IReadOnlyDictionary packages, IReadOnlyDictionary depots) { - if (apps == null) { - throw new ArgumentNullException(nameof(apps)); - } + ArgumentNullException.ThrowIfNull(apps); - if (packages == null) { - throw new ArgumentNullException(nameof(packages)); - } + ArgumentNullException.ThrowIfNull(packages); - if (depots == null) { - throw new ArgumentNullException(nameof(depots)); - } + ArgumentNullException.ThrowIfNull(depots); foreach ((uint appID, ulong token) in apps) { SubmittedApps[appID] = token; diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/RequestData.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/RequestData.cs index 2b43328f2..ea3b5579e 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/RequestData.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/RequestData.cs @@ -58,17 +58,11 @@ internal sealed class RequestData { throw new ArgumentOutOfRangeException(nameof(steamID)); } - if (apps == null) { - throw new ArgumentNullException(nameof(apps)); - } + ArgumentNullException.ThrowIfNull(apps); - if (accessTokens == null) { - throw new ArgumentNullException(nameof(accessTokens)); - } + ArgumentNullException.ThrowIfNull(accessTokens); - if (depots == null) { - throw new ArgumentNullException(nameof(depots)); - } + ArgumentNullException.ThrowIfNull(depots); SteamID = steamID; diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs index 21cb8ea78..8093dc018 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs @@ -145,9 +145,7 @@ internal sealed class SteamTokenDumperPlugin : OfficialPlugin, IASF, IBot, IBotS } public async Task OnBotDestroy(Bot bot) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if (BotSubscriptions.TryRemove(bot, out IDisposable? subscription)) { subscription.Dispose(); @@ -161,9 +159,7 @@ internal sealed class SteamTokenDumperPlugin : OfficialPlugin, IASF, IBot, IBotS } public async Task OnBotInit(Bot bot) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if (Config is not { Enabled: true }) { return; @@ -180,13 +176,9 @@ internal sealed class SteamTokenDumperPlugin : OfficialPlugin, IASF, IBot, IBotS } public Task OnBotSteamCallbacksInit(Bot bot, CallbackManager callbackManager) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); - if (callbackManager == null) { - throw new ArgumentNullException(nameof(callbackManager)); - } + ArgumentNullException.ThrowIfNull(callbackManager); if (BotSubscriptions.TryRemove(bot, out IDisposable? subscription)) { subscription.Dispose(); @@ -218,13 +210,9 @@ internal sealed class SteamTokenDumperPlugin : OfficialPlugin, IASF, IBot, IBotS throw new ArgumentOutOfRangeException(nameof(currentChangeNumber)); } - if (appChanges == null) { - throw new ArgumentNullException(nameof(appChanges)); - } + ArgumentNullException.ThrowIfNull(appChanges); - if (packageChanges == null) { - throw new ArgumentNullException(nameof(packageChanges)); - } + ArgumentNullException.ThrowIfNull(packageChanges); if (Config is not { Enabled: true }) { return Task.CompletedTask; @@ -266,13 +254,9 @@ internal sealed class SteamTokenDumperPlugin : OfficialPlugin, IASF, IBot, IBotS } private static async void OnLicenseList(Bot bot, SteamApps.LicenseListCallback callback) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); if (Config is not { Enabled: true }) { return; @@ -290,9 +274,7 @@ internal sealed class SteamTokenDumperPlugin : OfficialPlugin, IASF, IBot, IBotS } private static async Task Refresh(Bot bot, IReadOnlyCollection? packageIDs = null) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if (Config is not { Enabled: true }) { return; diff --git a/ArchiSteamFarm.Tests/Bot.cs b/ArchiSteamFarm.Tests/Bot.cs index 319c5f2a9..e30c10686 100644 --- a/ArchiSteamFarm.Tests/Bot.cs +++ b/ArchiSteamFarm.Tests/Bot.cs @@ -485,13 +485,9 @@ public sealed class Bot { } private static void AssertResultMatchesExpectation(IReadOnlyDictionary<(uint RealAppID, ulong ContextID, ulong ClassID), uint> expectedResult, IReadOnlyCollection itemsToSend) { - if (expectedResult == null) { - throw new ArgumentNullException(nameof(expectedResult)); - } + ArgumentNullException.ThrowIfNull(expectedResult); - if (itemsToSend == null) { - throw new ArgumentNullException(nameof(itemsToSend)); - } + ArgumentNullException.ThrowIfNull(itemsToSend); Dictionary<(uint RealAppID, ulong ContextID, ulong ClassID), long> realResult = itemsToSend.GroupBy(static asset => (asset.RealAppID, asset.ContextID, asset.ClassID)).ToDictionary(static group => group.Key, static group => group.Sum(static asset => asset.Amount)); Assert.AreEqual(expectedResult.Count, realResult.Count); diff --git a/ArchiSteamFarm.sln.DotSettings b/ArchiSteamFarm.sln.DotSettings index 548d991da..0b6cf07ee 100644 --- a/ArchiSteamFarm.sln.DotSettings +++ b/ArchiSteamFarm.sln.DotSettings @@ -7,7 +7,7 @@ True True ExplicitlyExcluded - + SOLUTION True SUGGESTION @@ -33,6 +33,7 @@ SUGGESTION SUGGESTION SUGGESTION + SUGGESTION SUGGESTION SUGGESTION SUGGESTION @@ -252,6 +253,7 @@ SUGGESTION SUGGESTION SUGGESTION + WARNING SUGGESTION SUGGESTION WARNING @@ -299,6 +301,7 @@ SUGGESTION SUGGESTION SUGGESTION + WARNING SUGGESTION WARNING WARNING @@ -308,7 +311,7 @@ Default Default Default - + <?xml version="1.0" encoding="utf-16"?><Profile name="Archi"><CSReorderTypeMembers>True</CSReorderTypeMembers><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><HtmlReformatCode>True</HtmlReformatCode><JsInsertSemicolon>True</JsInsertSemicolon><FormatAttributeQuoteDescriptor>True</FormatAttributeQuoteDescriptor><CorrectVariableKindsDescriptor>True</CorrectVariableKindsDescriptor><VariablesToInnerScopesDescriptor>True</VariablesToInnerScopesDescriptor><StringToTemplatesDescriptor>True</StringToTemplatesDescriptor><JsReformatCode>True</JsReformatCode><JsFormatDocComments>True</JsFormatDocComments><RemoveRedundantQualifiersTs>True</RemoveRedundantQualifiersTs><OptimizeImportsTs>True</OptimizeImportsTs><OptimizeReferenceCommentsTs>True</OptimizeReferenceCommentsTs><PublicModifierStyleTs>True</PublicModifierStyleTs><ExplicitAnyTs>True</ExplicitAnyTs><TypeAnnotationStyleTs>True</TypeAnnotationStyleTs><RelativePathStyleTs>True</RelativePathStyleTs><AsInsteadOfCastTs>True</AsInsteadOfCastTs><XMLReformatCode>True</XMLReformatCode><CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="True" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="True" ArrangeArgumentsStyle="True" ArrangeCodeBodyStyle="True" ArrangeVarStyle="True" ArrangeTrailingCommas="True" ArrangeObjectCreation="True" ArrangeDefaultValue="True" ArrangeNamespaces="True" /><RemoveCodeRedundanciesVB>True</RemoveCodeRedundanciesVB><CssAlphabetizeProperties>True</CssAlphabetizeProperties><VBOptimizeImports>True</VBOptimizeImports><VBShortenReferences>True</VBShortenReferences><RemoveCodeRedundancies>True</RemoveCodeRedundancies><CSUseAutoProperty>True</CSUseAutoProperty><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSMakeAutoPropertyGetOnly>True</CSMakeAutoPropertyGetOnly><CSArrangeQualifiers>True</CSArrangeQualifiers><CSFixBuiltinTypeReferences>True</CSFixBuiltinTypeReferences><CssReformatCode>True</CssReformatCode><VBReformatCode>True</VBReformatCode><VBFormatDocComments>True</VBFormatDocComments><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><CSharpFormatDocComments>True</CSharpFormatDocComments><CSUpdateFileHeader>True</CSUpdateFileHeader><Xaml.RedundantFreezeAttribute>True</Xaml.RedundantFreezeAttribute><Xaml.RemoveRedundantModifiersAttribute>True</Xaml.RemoveRedundantModifiersAttribute><Xaml.RemoveRedundantNameAttribute>True</Xaml.RemoveRedundantNameAttribute><Xaml.RemoveRedundantResource>True</Xaml.RemoveRedundantResource><Xaml.RemoveRedundantCollectionProperty>True</Xaml.RemoveRedundantCollectionProperty><Xaml.RemoveRedundantAttachedPropertySetter>True</Xaml.RemoveRedundantAttachedPropertySetter><Xaml.RemoveRedundantStyledValue>True</Xaml.RemoveRedundantStyledValue><Xaml.RemoveRedundantNamespaceAlias>True</Xaml.RemoveRedundantNamespaceAlias><Xaml.RemoveForbiddenResourceName>True</Xaml.RemoveForbiddenResourceName><Xaml.RemoveRedundantGridDefinitionsAttribute>True</Xaml.RemoveRedundantGridDefinitionsAttribute><Xaml.RemoveRedundantGridSpanAttribut>True</Xaml.RemoveRedundantGridSpanAttribut><Xaml.RemoveRedundantUpdateSourceTriggerAttribute>True</Xaml.RemoveRedundantUpdateSourceTriggerAttribute><Xaml.RemoveRedundantBindingModeAttribute>True</Xaml.RemoveRedundantBindingModeAttribute><CppAddTypenameTemplateKeywords>True</CppAddTypenameTemplateKeywords><CppJoinDeclarationAndAssignmentDescriptor>True</CppJoinDeclarationAndAssignmentDescriptor><CppMakeLocalVarConstDescriptor>True</CppMakeLocalVarConstDescriptor><CppMakeMethodConst>True</CppMakeMethodConst><CppMakeMethodStatic>True</CppMakeMethodStatic><CppRemoveElseKeyword>True</CppRemoveElseKeyword><CppRemoveRedundantMemberInitializerDescriptor>True</CppRemoveRedundantMemberInitializerDescriptor><CppRemoveRedundantParentheses>True</CppRemoveRedundantParentheses><CppShortenQualifiedName>True</CppShortenQualifiedName><CppDeleteRedundantSpecifier>True</CppDeleteRedundantSpecifier><CppRemoveStatement>True</CppRemoveStatement><CppRemoveTemplateArgumentsDescriptor>True</CppRemoveTemplateArgumentsDescriptor><CppDeleteRedundantTypenameTemplateKeywords>True</CppDeleteRedundantTypenameTemplateKeywords><CppRemoveUnreachableCode>True</CppRemoveUnreachableCode><CppRemoveUnusedIncludes>True</CppRemoveUnusedIncludes><CppRemoveUnusedLambdaCaptures>True</CppRemoveUnusedLambdaCaptures><CppCStyleToStaticCastDescriptor>True</CppCStyleToStaticCastDescriptor><CppReplaceExpressionWithBooleanConst>True</CppReplaceExpressionWithBooleanConst><CppMakeIfConstexpr>True</CppMakeIfConstexpr><CppMakePostfixOperatorPrefix>True</CppMakePostfixOperatorPrefix><CppChangeSmartPointerToMakeFunction>True</CppChangeSmartPointerToMakeFunction><CppReplaceThrowWithRethrowFix>True</CppReplaceThrowWithRethrowFix><CppReplaceExpressionWithNullptr>True</CppReplaceExpressionWithNullptr><CppCodeStyleCleanupDescriptor ArrangeAuto="True" ArrangeBraces="True" ArrangeCVQualifiers="True" ArrangeFunctionDeclarations="True" ArrangeNestedNamespaces="True" ArrangeOverridingFunctions="True" ArrangeSlashesInIncludeDirectives="True" ArrangeTypeAliases="True" SortIncludeDirectives="True" SortMemberInitializers="True" /><CppReformatCode>True</CppReformatCode><CppUpdateFileHeader>True</CppUpdateFileHeader><IDEA_SETTINGS>&lt;profile version="1.0"&gt; &lt;option name="myName" value="Archi" /&gt; &lt;inspection_tool class="ConditionalExpressionWithIdenticalBranchesJS" enabled="true" level="WARNING" enabled_by_default="true" /&gt; @@ -383,13 +386,13 @@ ExpressionBody ExpressionBody public protected internal private static extern new virtual abstract sealed override readonly unsafe volatile async - + Arithmetic, Shift, Bitwise, Conditional END_OF_LINE END_OF_LINE USE_TABS_ONLY False - + END_OF_LINE 1 1 @@ -412,7 +415,7 @@ False True False - + True 1 @@ -757,7 +760,7 @@ limitations under the License. LIVE_MONITOR NOTIFY NOTIFY - + True NOTIFY diff --git a/ArchiSteamFarm/Collections/ConcurrentEnumerator.cs b/ArchiSteamFarm/Collections/ConcurrentEnumerator.cs index 029474320..17fd69177 100644 --- a/ArchiSteamFarm/Collections/ConcurrentEnumerator.cs +++ b/ArchiSteamFarm/Collections/ConcurrentEnumerator.cs @@ -34,9 +34,7 @@ internal sealed class ConcurrentEnumerator : IEnumerator { object? IEnumerator.Current => Current; internal ConcurrentEnumerator(IReadOnlyCollection collection, IDisposable lockObject) { - if (collection == null) { - throw new ArgumentNullException(nameof(collection)); - } + ArgumentNullException.ThrowIfNull(collection); LockObject = lockObject ?? throw new ArgumentNullException(nameof(lockObject)); Enumerator = collection.GetEnumerator(); diff --git a/ArchiSteamFarm/Collections/ConcurrentHashSet.cs b/ArchiSteamFarm/Collections/ConcurrentHashSet.cs index cac0fe8d0..8c10620b2 100644 --- a/ArchiSteamFarm/Collections/ConcurrentHashSet.cs +++ b/ArchiSteamFarm/Collections/ConcurrentHashSet.cs @@ -39,9 +39,7 @@ public sealed class ConcurrentHashSet : IReadOnlyCollection, ISet where public ConcurrentHashSet() => BackingCollection = new ConcurrentDictionary(); public ConcurrentHashSet(IEqualityComparer comparer) { - if (comparer == null) { - throw new ArgumentNullException(nameof(comparer)); - } + ArgumentNullException.ThrowIfNull(comparer); BackingCollection = new ConcurrentDictionary(comparer); } @@ -71,9 +69,7 @@ public sealed class ConcurrentHashSet : IReadOnlyCollection, ISet where public void CopyTo(T[] array, int arrayIndex) => BackingCollection.Keys.CopyTo(array, arrayIndex); public void ExceptWith(IEnumerable other) { - if (other == null) { - throw new ArgumentNullException(nameof(other)); - } + ArgumentNullException.ThrowIfNull(other); foreach (T item in other) { Remove(item); @@ -151,9 +147,7 @@ public sealed class ConcurrentHashSet : IReadOnlyCollection, ISet where } public void UnionWith(IEnumerable other) { - if (other == null) { - throw new ArgumentNullException(nameof(other)); - } + ArgumentNullException.ThrowIfNull(other); foreach (T otherElement in other) { Add(otherElement); diff --git a/ArchiSteamFarm/Core/ASF.cs b/ArchiSteamFarm/Core/ASF.cs index a99cccd84..1f365980b 100644 --- a/ArchiSteamFarm/Core/ASF.cs +++ b/ArchiSteamFarm/Core/ASF.cs @@ -485,13 +485,9 @@ public static class ASF { private static async void OnAutoUpdatesTimer(object? state = null) => await UpdateAndRestart().ConfigureAwait(false); private static async void OnChanged(object sender, FileSystemEventArgs e) { - if (sender == null) { - throw new ArgumentNullException(nameof(sender)); - } + ArgumentNullException.ThrowIfNull(sender); - if (e == null) { - throw new ArgumentNullException(nameof(e)); - } + ArgumentNullException.ThrowIfNull(e); if (string.IsNullOrEmpty(e.Name)) { throw new InvalidOperationException(nameof(e.Name)); @@ -571,13 +567,9 @@ public static class ASF { } private static async void OnCreated(object sender, FileSystemEventArgs e) { - if (sender == null) { - throw new ArgumentNullException(nameof(sender)); - } + ArgumentNullException.ThrowIfNull(sender); - if (e == null) { - throw new ArgumentNullException(nameof(e)); - } + ArgumentNullException.ThrowIfNull(e); if (string.IsNullOrEmpty(e.Name)) { throw new InvalidOperationException(nameof(e.Name)); @@ -713,13 +705,9 @@ public static class ASF { } private static async void OnDeleted(object sender, FileSystemEventArgs e) { - if (sender == null) { - throw new ArgumentNullException(nameof(sender)); - } + ArgumentNullException.ThrowIfNull(sender); - if (e == null) { - throw new ArgumentNullException(nameof(e)); - } + ArgumentNullException.ThrowIfNull(e); if (string.IsNullOrEmpty(e.Name)) { throw new InvalidOperationException(nameof(e.Name)); @@ -837,13 +825,9 @@ public static class ASF { } private static async void OnRenamed(object sender, RenamedEventArgs e) { - if (sender == null) { - throw new ArgumentNullException(nameof(sender)); - } + ArgumentNullException.ThrowIfNull(sender); - if (e == null) { - throw new ArgumentNullException(nameof(e)); - } + ArgumentNullException.ThrowIfNull(e); if (string.IsNullOrEmpty(e.OldName)) { throw new InvalidOperationException(nameof(e.OldName)); @@ -953,9 +937,7 @@ public static class ASF { } private static bool UpdateFromArchive(ZipArchive archive, string targetDirectory) { - if (archive == null) { - throw new ArgumentNullException(nameof(archive)); - } + ArgumentNullException.ThrowIfNull(archive); if (string.IsNullOrEmpty(targetDirectory)) { throw new ArgumentNullException(nameof(targetDirectory)); diff --git a/ArchiSteamFarm/Core/ArchiNet.cs b/ArchiSteamFarm/Core/ArchiNet.cs index 1c837d015..63f4b051e 100644 --- a/ArchiSteamFarm/Core/ArchiNet.cs +++ b/ArchiSteamFarm/Core/ArchiNet.cs @@ -41,9 +41,7 @@ internal static class ArchiNet { private static Uri URL => new("https://asf.JustArchi.net"); internal static async Task AnnounceForListing(Bot bot, IReadOnlyCollection inventory, IReadOnlyCollection acceptedMatchableTypes, string tradeToken, string? nickname = null, string? avatarHash = null) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((inventory == null) || (inventory.Count == 0)) { throw new ArgumentNullException(nameof(inventory)); @@ -105,9 +103,7 @@ internal static class ArchiNet { } internal static async Task?> GetListedUsers(Bot bot) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); Uri request = new(URL, "/Api/Bots"); @@ -117,9 +113,7 @@ internal static class ArchiNet { } internal static async Task HeartBeatForListing(Bot bot) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); Uri request = new(URL, "/Api/HeartBeat"); diff --git a/ArchiSteamFarm/Core/Statistics.cs b/ArchiSteamFarm/Core/Statistics.cs index 5f93109f5..20160893d 100644 --- a/ArchiSteamFarm/Core/Statistics.cs +++ b/ArchiSteamFarm/Core/Statistics.cs @@ -342,9 +342,7 @@ internal sealed class Statistics : IAsyncDisposable { throw new ArgumentNullException(nameof(acceptedMatchableTypes)); } - if (triedSteamIDs == null) { - throw new ArgumentNullException(nameof(triedSteamIDs)); - } + ArgumentNullException.ThrowIfNull(triedSteamIDs); HashSet ourInventory; diff --git a/ArchiSteamFarm/Core/Utilities.cs b/ArchiSteamFarm/Core/Utilities.cs index ed5d850bc..17ad93a16 100644 --- a/ArchiSteamFarm/Core/Utilities.cs +++ b/ArchiSteamFarm/Core/Utilities.cs @@ -51,9 +51,7 @@ public static class Utilities { [PublicAPI] public static string GetArgsAsText(string[] args, byte argsToSkip, string delimiter) { - if (args == null) { - throw new ArgumentNullException(nameof(args)); - } + ArgumentNullException.ThrowIfNull(args); if (args.Length <= argsToSkip) { throw new InvalidOperationException($"{nameof(args.Length)} && {nameof(argsToSkip)}"); @@ -79,9 +77,7 @@ public static class Utilities { [PublicAPI] public static string? GetCookieValue(this CookieContainer cookieContainer, Uri uri, string name) { - if (cookieContainer == null) { - throw new ArgumentNullException(nameof(cookieContainer)); - } + ArgumentNullException.ThrowIfNull(cookieContainer); if (uri == null) { throw new ArgumentNullException(nameof(uri)); @@ -105,9 +101,7 @@ public static class Utilities { [PublicAPI] public static async void InBackground(Action action, bool longRunning = false) { - if (action == null) { - throw new ArgumentNullException(nameof(action)); - } + ArgumentNullException.ThrowIfNull(action); TaskCreationOptions options = TaskCreationOptions.DenyChildAttach; @@ -120,9 +114,7 @@ public static class Utilities { [PublicAPI] public static async void InBackground(Func function, bool longRunning = false) { - if (function == null) { - throw new ArgumentNullException(nameof(function)); - } + ArgumentNullException.ThrowIfNull(function); TaskCreationOptions options = TaskCreationOptions.DenyChildAttach; @@ -135,9 +127,7 @@ public static class Utilities { [PublicAPI] public static async Task> InParallel(IEnumerable> tasks) { - if (tasks == null) { - throw new ArgumentNullException(nameof(tasks)); - } + ArgumentNullException.ThrowIfNull(tasks); IList results; @@ -161,9 +151,7 @@ public static class Utilities { [PublicAPI] public static async Task InParallel(IEnumerable tasks) { - if (tasks == null) { - throw new ArgumentNullException(nameof(tasks)); - } + ArgumentNullException.ThrowIfNull(tasks); switch (ASF.GlobalConfig?.OptimizationMode) { case GlobalConfig.EOptimizationMode.MinMemoryUsage: @@ -208,9 +196,7 @@ public static class Utilities { [PublicAPI] public static IEnumerable SelectNodes(this IDocument document, string xpath) { - if (document == null) { - throw new ArgumentNullException(nameof(document)); - } + ArgumentNullException.ThrowIfNull(document); return document.Body.SelectNodes(xpath).OfType(); } @@ -220,9 +206,7 @@ public static class Utilities { [PublicAPI] public static IElement? SelectSingleNode(this IDocument document, string xpath) { - if (document == null) { - throw new ArgumentNullException(nameof(document)); - } + ArgumentNullException.ThrowIfNull(document); return (IElement?) document.Body.SelectSingleNode(xpath); } @@ -237,9 +221,7 @@ public static class Utilities { [PublicAPI] public static Task ToLongRunningTask(this AsyncJob job) where T : CallbackMsg { - if (job == null) { - throw new ArgumentNullException(nameof(job)); - } + ArgumentNullException.ThrowIfNull(job); job.Timeout = TimeSpan.FromSeconds(TimeoutForLongRunningTasksInSeconds); @@ -248,9 +230,7 @@ public static class Utilities { [PublicAPI] public static Task.ResultSet> ToLongRunningTask(this AsyncJobMultiple job) where T : CallbackMsg { - if (job == null) { - throw new ArgumentNullException(nameof(job)); - } + ArgumentNullException.ThrowIfNull(job); job.Timeout = TimeSpan.FromSeconds(TimeoutForLongRunningTasksInSeconds); @@ -311,9 +291,7 @@ public static class Utilities { } internal static void WarnAboutIncompleteTranslation(ResourceManager resourceManager) { - if (resourceManager == null) { - throw new ArgumentNullException(nameof(resourceManager)); - } + ArgumentNullException.ThrowIfNull(resourceManager); // Skip translation progress for English and invariant (such as "C") cultures switch (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName) { diff --git a/ArchiSteamFarm/IPC/Controllers/Api/ASFController.cs b/ArchiSteamFarm/IPC/Controllers/Api/ASFController.cs index 7e5d01f28..0cf846b32 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/ASFController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/ASFController.cs @@ -46,9 +46,7 @@ public sealed class ASFController : ArchiController { [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)] [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)] public ActionResult ASFEncryptPost([FromBody] ASFEncryptRequest request) { - if (request == null) { - throw new ArgumentNullException(nameof(request)); - } + ArgumentNullException.ThrowIfNull(request); if (string.IsNullOrEmpty(request.StringToEncrypt)) { return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.StringToEncrypt)))); @@ -84,9 +82,7 @@ public sealed class ASFController : ArchiController { [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)] [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)] public ActionResult ASFHashPost([FromBody] ASFHashRequest request) { - if (request == null) { - throw new ArgumentNullException(nameof(request)); - } + ArgumentNullException.ThrowIfNull(request); if (string.IsNullOrEmpty(request.StringToHash)) { return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.StringToHash)))); @@ -105,9 +101,7 @@ public sealed class ASFController : ArchiController { [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)] [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)] public async Task> ASFPost([FromBody] ASFRequest request) { - if (request == null) { - throw new ArgumentNullException(nameof(request)); - } + ArgumentNullException.ThrowIfNull(request); if (ASF.GlobalConfig == null) { throw new InvalidOperationException(nameof(ASF.GlobalConfig)); diff --git a/ArchiSteamFarm/IPC/Controllers/Api/BotController.cs b/ArchiSteamFarm/IPC/Controllers/Api/BotController.cs index c13859ae4..04b2434bf 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/BotController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/BotController.cs @@ -94,9 +94,7 @@ public sealed class BotController : ArchiController { throw new ArgumentNullException(nameof(botNames)); } - if (request == null) { - throw new ArgumentNullException(nameof(request)); - } + ArgumentNullException.ThrowIfNull(request); if (Bot.Bots == null) { throw new InvalidOperationException(nameof(Bot.Bots)); @@ -220,9 +218,7 @@ public sealed class BotController : ArchiController { throw new ArgumentNullException(nameof(botNames)); } - if (request == null) { - throw new ArgumentNullException(nameof(request)); - } + ArgumentNullException.ThrowIfNull(request); if (request.GamesToRedeemInBackground.Count == 0) { return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.GamesToRedeemInBackground)))); @@ -263,9 +259,7 @@ public sealed class BotController : ArchiController { throw new ArgumentNullException(nameof(botNames)); } - if (request == null) { - throw new ArgumentNullException(nameof(request)); - } + ArgumentNullException.ThrowIfNull(request); if ((request.Type == ASF.EUserInputType.None) || !Enum.IsDefined(typeof(ASF.EUserInputType), request.Type) || string.IsNullOrEmpty(request.Value)) { return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, $"{nameof(request.Type)} || {nameof(request.Value)}"))); @@ -294,9 +288,7 @@ public sealed class BotController : ArchiController { throw new ArgumentNullException(nameof(botNames)); } - if (request == null) { - throw new ArgumentNullException(nameof(request)); - } + ArgumentNullException.ThrowIfNull(request); HashSet? bots = Bot.GetBots(botNames); @@ -325,9 +317,7 @@ public sealed class BotController : ArchiController { throw new ArgumentNullException(nameof(botNames)); } - if (request == null) { - throw new ArgumentNullException(nameof(request)); - } + ArgumentNullException.ThrowIfNull(request); if (request.KeysToRedeem.Count == 0) { return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.KeysToRedeem)))); @@ -369,9 +359,7 @@ public sealed class BotController : ArchiController { throw new ArgumentNullException(nameof(botName)); } - if (request == null) { - throw new ArgumentNullException(nameof(request)); - } + ArgumentNullException.ThrowIfNull(request); if (Bot.Bots == null) { throw new InvalidOperationException(nameof(Bot.Bots)); diff --git a/ArchiSteamFarm/IPC/Controllers/Api/CommandController.cs b/ArchiSteamFarm/IPC/Controllers/Api/CommandController.cs index 8da15275d..1faad2298 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/CommandController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/CommandController.cs @@ -48,9 +48,7 @@ public sealed class CommandController : ArchiController { [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)] [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)] public async Task> CommandPost([FromBody] CommandRequest request) { - if (request == null) { - throw new ArgumentNullException(nameof(request)); - } + ArgumentNullException.ThrowIfNull(request); if (string.IsNullOrEmpty(request.Command)) { return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.Command)))); diff --git a/ArchiSteamFarm/IPC/Controllers/Api/NLogController.cs b/ArchiSteamFarm/IPC/Controllers/Api/NLogController.cs index 64f92322f..67596c742 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/NLogController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/NLogController.cs @@ -112,9 +112,7 @@ public sealed class NLogController : ArchiController { } internal static async void OnNewHistoryEntry(object? sender, HistoryTarget.NewHistoryEntryArgs newHistoryEntryArgs) { - if (newHistoryEntryArgs == null) { - throw new ArgumentNullException(nameof(newHistoryEntryArgs)); - } + ArgumentNullException.ThrowIfNull(newHistoryEntryArgs); if (ActiveLogWebSockets.IsEmpty) { return; @@ -126,17 +124,13 @@ public sealed class NLogController : ArchiController { } private static async Task PostLoggedJsonUpdate(WebSocket webSocket, string json, SemaphoreSlim sendSemaphore, CancellationToken cancellationToken) { - if (webSocket == null) { - throw new ArgumentNullException(nameof(webSocket)); - } + ArgumentNullException.ThrowIfNull(webSocket); if (string.IsNullOrEmpty(json)) { throw new ArgumentNullException(nameof(json)); } - if (sendSemaphore == null) { - throw new ArgumentNullException(nameof(sendSemaphore)); - } + ArgumentNullException.ThrowIfNull(sendSemaphore); if (cancellationToken.IsCancellationRequested || (webSocket.State != WebSocketState.Open)) { return; @@ -170,17 +164,13 @@ public sealed class NLogController : ArchiController { } private static async Task PostLoggedMessageUpdate(WebSocket webSocket, string loggedMessage, SemaphoreSlim sendSemaphore, CancellationToken cancellationToken) { - if (webSocket == null) { - throw new ArgumentNullException(nameof(webSocket)); - } + ArgumentNullException.ThrowIfNull(webSocket); if (string.IsNullOrEmpty(loggedMessage)) { throw new ArgumentNullException(nameof(loggedMessage)); } - if (sendSemaphore == null) { - throw new ArgumentNullException(nameof(sendSemaphore)); - } + ArgumentNullException.ThrowIfNull(sendSemaphore); if (cancellationToken.IsCancellationRequested || (webSocket.State != WebSocketState.Open)) { return; diff --git a/ArchiSteamFarm/IPC/Controllers/Api/StorageController.cs b/ArchiSteamFarm/IPC/Controllers/Api/StorageController.cs index 129856851..204571e18 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/StorageController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/StorageController.cs @@ -79,9 +79,7 @@ public sealed class StorageController : ArchiController { throw new ArgumentNullException(nameof(key)); } - if (value == null) { - throw new ArgumentNullException(nameof(value)); - } + ArgumentNullException.ThrowIfNull(value); if (ASF.GlobalDatabase == null) { throw new InvalidOperationException(nameof(ASF.GlobalDatabase)); diff --git a/ArchiSteamFarm/IPC/Controllers/Api/TwoFactorAuthenticationController.cs b/ArchiSteamFarm/IPC/Controllers/Api/TwoFactorAuthenticationController.cs index bd83d5f4a..6b1cd733b 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/TwoFactorAuthenticationController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/TwoFactorAuthenticationController.cs @@ -49,9 +49,7 @@ public sealed class TwoFactorAuthenticationController : ArchiController { throw new ArgumentNullException(nameof(botNames)); } - if (request == null) { - throw new ArgumentNullException(nameof(request)); - } + ArgumentNullException.ThrowIfNull(request); if (request.AcceptedType.HasValue && ((request.AcceptedType.Value == Confirmation.EType.Unknown) || !Enum.IsDefined(typeof(Confirmation.EType), request.AcceptedType.Value))) { return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(request.AcceptedType)))); @@ -116,9 +114,7 @@ public sealed class TwoFactorAuthenticationController : ArchiController { throw new ArgumentNullException(nameof(botNames)); } - if (authenticator == null) { - throw new ArgumentNullException(nameof(authenticator)); - } + ArgumentNullException.ThrowIfNull(authenticator); HashSet? bots = Bot.GetBots(botNames); diff --git a/ArchiSteamFarm/IPC/Integration/ApiAuthenticationMiddleware.cs b/ArchiSteamFarm/IPC/Integration/ApiAuthenticationMiddleware.cs index 94fb4f590..4c6bd5248 100644 --- a/ArchiSteamFarm/IPC/Integration/ApiAuthenticationMiddleware.cs +++ b/ArchiSteamFarm/IPC/Integration/ApiAuthenticationMiddleware.cs @@ -59,9 +59,7 @@ internal sealed class ApiAuthenticationMiddleware { public ApiAuthenticationMiddleware(RequestDelegate next, IOptions forwardedHeadersOptions) { Next = next ?? throw new ArgumentNullException(nameof(next)); - if (forwardedHeadersOptions == null) { - throw new ArgumentNullException(nameof(forwardedHeadersOptions)); - } + ArgumentNullException.ThrowIfNull(forwardedHeadersOptions); ForwardedHeadersOptions = forwardedHeadersOptions.Value ?? throw new InvalidOperationException(nameof(forwardedHeadersOptions)); @@ -72,13 +70,9 @@ internal sealed class ApiAuthenticationMiddleware { [UsedImplicitly] public async Task InvokeAsync(HttpContext context, IOptions jsonOptions) { - if (context == null) { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (jsonOptions == null) { - throw new ArgumentNullException(nameof(jsonOptions)); - } + ArgumentNullException.ThrowIfNull(jsonOptions); (HttpStatusCode statusCode, bool permanent) = await GetAuthenticationStatus(context).ConfigureAwait(false); @@ -98,9 +92,7 @@ internal sealed class ApiAuthenticationMiddleware { private static void ClearFailedAuthorizations(object? state = null) => FailedAuthorizations.Clear(); private async Task<(HttpStatusCode StatusCode, bool Permanent)> GetAuthenticationStatus(HttpContext context) { - if (context == null) { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); IPAddress? clientIP = context.Connection.RemoteIpAddress; diff --git a/ArchiSteamFarm/IPC/Integration/CustomAttributesSchemaFilter.cs b/ArchiSteamFarm/IPC/Integration/CustomAttributesSchemaFilter.cs index 443d9f194..a6aa8a938 100644 --- a/ArchiSteamFarm/IPC/Integration/CustomAttributesSchemaFilter.cs +++ b/ArchiSteamFarm/IPC/Integration/CustomAttributesSchemaFilter.cs @@ -30,13 +30,9 @@ namespace ArchiSteamFarm.IPC.Integration; [UsedImplicitly] internal sealed class CustomAttributesSchemaFilter : ISchemaFilter { public void Apply(OpenApiSchema schema, SchemaFilterContext context) { - if (schema == null) { - throw new ArgumentNullException(nameof(schema)); - } + ArgumentNullException.ThrowIfNull(schema); - if (context == null) { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); ICustomAttributeProvider attributesProvider; diff --git a/ArchiSteamFarm/IPC/Integration/EnumSchemaFilter.cs b/ArchiSteamFarm/IPC/Integration/EnumSchemaFilter.cs index 03f1784f9..0ac00ffb1 100644 --- a/ArchiSteamFarm/IPC/Integration/EnumSchemaFilter.cs +++ b/ArchiSteamFarm/IPC/Integration/EnumSchemaFilter.cs @@ -32,13 +32,9 @@ namespace ArchiSteamFarm.IPC.Integration; [UsedImplicitly] internal sealed class EnumSchemaFilter : ISchemaFilter { public void Apply(OpenApiSchema schema, SchemaFilterContext context) { - if (schema == null) { - throw new ArgumentNullException(nameof(schema)); - } + ArgumentNullException.ThrowIfNull(schema); - if (context == null) { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); if (context.Type is not { IsEnum: true }) { return; @@ -91,9 +87,7 @@ internal sealed class EnumSchemaFilter : ISchemaFilter { } private static bool TryCast(object value, out T typedValue) where T : struct { - if (value == null) { - throw new ArgumentNullException(nameof(value)); - } + ArgumentNullException.ThrowIfNull(value); try { typedValue = (T) Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture); diff --git a/ArchiSteamFarm/IPC/Integration/LocalizationMiddleware.cs b/ArchiSteamFarm/IPC/Integration/LocalizationMiddleware.cs index 693975239..1481a588c 100644 --- a/ArchiSteamFarm/IPC/Integration/LocalizationMiddleware.cs +++ b/ArchiSteamFarm/IPC/Integration/LocalizationMiddleware.cs @@ -45,9 +45,7 @@ internal sealed class LocalizationMiddleware { [UsedImplicitly] public async Task InvokeAsync(HttpContext context) { - if (context == null) { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); RequestHeaders headers = context.Request.GetTypedHeaders(); diff --git a/ArchiSteamFarm/IPC/Integration/SwaggerItemsMinMaxAttribute.cs b/ArchiSteamFarm/IPC/Integration/SwaggerItemsMinMaxAttribute.cs index d1804bee4..d45f13a20 100644 --- a/ArchiSteamFarm/IPC/Integration/SwaggerItemsMinMaxAttribute.cs +++ b/ArchiSteamFarm/IPC/Integration/SwaggerItemsMinMaxAttribute.cs @@ -41,9 +41,7 @@ public sealed class SwaggerItemsMinMaxAttribute : CustomSwaggerAttribute { private decimal? BackingMinimum; public override void Apply(OpenApiSchema schema) { - if (schema == null) { - throw new ArgumentNullException(nameof(schema)); - } + ArgumentNullException.ThrowIfNull(schema); if (schema.Items == null) { throw new InvalidOperationException(nameof(schema.Items)); diff --git a/ArchiSteamFarm/IPC/Integration/SwaggerSteamIdentifierAttribute.cs b/ArchiSteamFarm/IPC/Integration/SwaggerSteamIdentifierAttribute.cs index c2e8212f0..19beecec7 100644 --- a/ArchiSteamFarm/IPC/Integration/SwaggerSteamIdentifierAttribute.cs +++ b/ArchiSteamFarm/IPC/Integration/SwaggerSteamIdentifierAttribute.cs @@ -34,9 +34,7 @@ public sealed class SwaggerSteamIdentifierAttribute : CustomSwaggerAttribute { public EUniverse Universe { get; set; } = EUniverse.Public; public override void Apply(OpenApiSchema schema) { - if (schema == null) { - throw new ArgumentNullException(nameof(schema)); - } + ArgumentNullException.ThrowIfNull(schema); schema.Minimum = new SteamID(MinimumAccountID, Universe, AccountType); schema.Maximum = new SteamID(MaximumAccountID, Universe, AccountType); diff --git a/ArchiSteamFarm/IPC/Integration/SwaggerValidValuesAttribute.cs b/ArchiSteamFarm/IPC/Integration/SwaggerValidValuesAttribute.cs index 9cbd4fe4b..823e5ef27 100644 --- a/ArchiSteamFarm/IPC/Integration/SwaggerValidValuesAttribute.cs +++ b/ArchiSteamFarm/IPC/Integration/SwaggerValidValuesAttribute.cs @@ -34,9 +34,7 @@ public sealed class SwaggerValidValuesAttribute : CustomSwaggerAttribute { public string[]? ValidStringValues { get; set; } public override void Apply(OpenApiSchema schema) { - if (schema == null) { - throw new ArgumentNullException(nameof(schema)); - } + ArgumentNullException.ThrowIfNull(schema); OpenApiArray validValues = new(); diff --git a/ArchiSteamFarm/IPC/Requests/TwoFactorAuthenticationConfirmationsRequest.cs b/ArchiSteamFarm/IPC/Requests/TwoFactorAuthenticationConfirmationsRequest.cs index 244e66c53..3550b59c0 100644 --- a/ArchiSteamFarm/IPC/Requests/TwoFactorAuthenticationConfirmationsRequest.cs +++ b/ArchiSteamFarm/IPC/Requests/TwoFactorAuthenticationConfirmationsRequest.cs @@ -59,9 +59,7 @@ public sealed class TwoFactorAuthenticationConfirmationsRequest { public ImmutableHashSet SAcceptedCreatorIDs { get => AcceptedCreatorIDs.Select(static creatorID => creatorID.ToString(CultureInfo.InvariantCulture)).ToImmutableHashSet(); set { - if (value == null) { - throw new ArgumentNullException(nameof(value)); - } + ArgumentNullException.ThrowIfNull(value); HashSet acceptedCreatorIDs = new(); diff --git a/ArchiSteamFarm/IPC/Responses/GitHubReleaseResponse.cs b/ArchiSteamFarm/IPC/Responses/GitHubReleaseResponse.cs index 0a757a1b9..65729b1bf 100644 --- a/ArchiSteamFarm/IPC/Responses/GitHubReleaseResponse.cs +++ b/ArchiSteamFarm/IPC/Responses/GitHubReleaseResponse.cs @@ -56,9 +56,7 @@ public sealed class GitHubReleaseResponse { public string Version { get; private set; } internal GitHubReleaseResponse(GitHub.ReleaseResponse releaseResponse) { - if (releaseResponse == null) { - throw new ArgumentNullException(nameof(releaseResponse)); - } + ArgumentNullException.ThrowIfNull(releaseResponse); ChangelogHTML = releaseResponse.ChangelogHTML ?? ""; ReleasedAt = releaseResponse.PublishedAt; diff --git a/ArchiSteamFarm/IPC/Startup.cs b/ArchiSteamFarm/IPC/Startup.cs index c07df13df..03306ad8e 100644 --- a/ArchiSteamFarm/IPC/Startup.cs +++ b/ArchiSteamFarm/IPC/Startup.cs @@ -62,13 +62,9 @@ internal sealed class Startup { [UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "PathString is a primitive, it's unlikely to be trimmed to the best of our knowledge")] [UsedImplicitly] public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - if (app == null) { - throw new ArgumentNullException(nameof(app)); - } + ArgumentNullException.ThrowIfNull(app); - if (env == null) { - throw new ArgumentNullException(nameof(env)); - } + ArgumentNullException.ThrowIfNull(env); // The order of dependency injection is super important, doing things in wrong order will break everything // https://docs.microsoft.com/aspnet/core/fundamentals/middleware @@ -189,9 +185,7 @@ internal sealed class Startup { [UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "HashSet isn't a primitive, but we widely use the required features everywhere and it's unlikely to be trimmed to the best of our knowledge")] public void ConfigureServices(IServiceCollection services) { - if (services == null) { - throw new ArgumentNullException(nameof(services)); - } + ArgumentNullException.ThrowIfNull(services); // The order of dependency injection is super important, doing things in wrong order will break everything // Order in Configure() method is a good start diff --git a/ArchiSteamFarm/IPC/WebUtilities.cs b/ArchiSteamFarm/IPC/WebUtilities.cs index 74be6e8eb..4154a935b 100644 --- a/ArchiSteamFarm/IPC/WebUtilities.cs +++ b/ArchiSteamFarm/IPC/WebUtilities.cs @@ -76,9 +76,7 @@ internal static class WebUtilities { #endif internal static string? GetUnifiedName(this Type type) { - if (type == null) { - throw new ArgumentNullException(nameof(type)); - } + ArgumentNullException.ThrowIfNull(type); return type.GenericTypeArguments.Length == 0 ? type.FullName : $"{type.Namespace}.{type.Name}{string.Join("", type.GenericTypeArguments.Select(static innerType => $"[{innerType.GetUnifiedName()}]"))}"; } @@ -106,9 +104,7 @@ internal static class WebUtilities { } internal static async Task WriteJsonAsync(this HttpResponse response, TValue? value, JsonSerializerSettings? jsonSerializerSettings = null) { - if (response == null) { - throw new ArgumentNullException(nameof(response)); - } + ArgumentNullException.ThrowIfNull(response); JsonSerializer serializer = JsonSerializer.CreateDefault(jsonSerializerSettings); diff --git a/ArchiSteamFarm/NLog/ArchiLogger.cs b/ArchiSteamFarm/NLog/ArchiLogger.cs index c5593f196..c87c67a44 100644 --- a/ArchiSteamFarm/NLog/ArchiLogger.cs +++ b/ArchiSteamFarm/NLog/ArchiLogger.cs @@ -55,9 +55,7 @@ public sealed class ArchiLogger { [PublicAPI] public void LogGenericDebuggingException(Exception exception, [CallerMemberName] string? previousMethodName = null) { - if (exception == null) { - throw new ArgumentNullException(nameof(exception)); - } + ArgumentNullException.ThrowIfNull(exception); if (!Debugging.IsUserDebugging) { return; @@ -77,9 +75,7 @@ public sealed class ArchiLogger { [PublicAPI] public void LogGenericException(Exception exception, [CallerMemberName] string? previousMethodName = null) { - if (exception == null) { - throw new ArgumentNullException(nameof(exception)); - } + ArgumentNullException.ThrowIfNull(exception); Logger.Error(exception, $"{previousMethodName}()"); } @@ -113,9 +109,7 @@ public sealed class ArchiLogger { [PublicAPI] public void LogGenericWarningException(Exception exception, [CallerMemberName] string? previousMethodName = null) { - if (exception == null) { - throw new ArgumentNullException(nameof(exception)); - } + ArgumentNullException.ThrowIfNull(exception); Logger.Warn(exception, $"{previousMethodName}()"); } @@ -164,9 +158,7 @@ public sealed class ArchiLogger { } internal async Task LogFatalException(Exception exception, [CallerMemberName] string? previousMethodName = null) { - if (exception == null) { - throw new ArgumentNullException(nameof(exception)); - } + ArgumentNullException.ThrowIfNull(exception); Logger.Fatal(exception, $"{previousMethodName}()"); diff --git a/ArchiSteamFarm/NLog/Logging.cs b/ArchiSteamFarm/NLog/Logging.cs index 2e6f1c56f..248b90e63 100644 --- a/ArchiSteamFarm/NLog/Logging.cs +++ b/ArchiSteamFarm/NLog/Logging.cs @@ -406,9 +406,7 @@ internal static class Logging { } private static void OnConfigurationChanged(object? sender, LoggingConfigurationChangedEventArgs e) { - if (e == null) { - throw new ArgumentNullException(nameof(e)); - } + ArgumentNullException.ThrowIfNull(e); InitConsoleLoggers(); diff --git a/ArchiSteamFarm/NLog/Targets/HistoryTarget.cs b/ArchiSteamFarm/NLog/Targets/HistoryTarget.cs index a160e435a..ba093363e 100644 --- a/ArchiSteamFarm/NLog/Targets/HistoryTarget.cs +++ b/ArchiSteamFarm/NLog/Targets/HistoryTarget.cs @@ -63,9 +63,7 @@ internal sealed class HistoryTarget : TargetWithLayout { internal HistoryTarget(string name) : this() => Name = name; protected override void Write(LogEventInfo logEvent) { - if (logEvent == null) { - throw new ArgumentNullException(nameof(logEvent)); - } + ArgumentNullException.ThrowIfNull(logEvent); base.Write(logEvent); diff --git a/ArchiSteamFarm/NLog/Targets/SteamTarget.cs b/ArchiSteamFarm/NLog/Targets/SteamTarget.cs index 95b8576a2..421ccce50 100644 --- a/ArchiSteamFarm/NLog/Targets/SteamTarget.cs +++ b/ArchiSteamFarm/NLog/Targets/SteamTarget.cs @@ -59,9 +59,7 @@ internal sealed class SteamTarget : AsyncTaskTarget { public SteamTarget() => Layout = "${level:uppercase=true}|${logger}|${message}"; protected override async Task WriteAsyncTask(LogEventInfo logEvent, CancellationToken cancellationToken) { - if (logEvent == null) { - throw new ArgumentNullException(nameof(logEvent)); - } + ArgumentNullException.ThrowIfNull(logEvent); base.Write(logEvent); diff --git a/ArchiSteamFarm/Plugins/PluginsCore.cs b/ArchiSteamFarm/Plugins/PluginsCore.cs index 30b281c41..141ade303 100644 --- a/ArchiSteamFarm/Plugins/PluginsCore.cs +++ b/ArchiSteamFarm/Plugins/PluginsCore.cs @@ -267,9 +267,7 @@ internal static class PluginsCore { } internal static async Task OnBotCommand(Bot bot, ulong steamID, string message, string[] args) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { throw new ArgumentOutOfRangeException(nameof(steamID)); @@ -301,9 +299,7 @@ internal static class PluginsCore { } internal static async Task OnBotDestroy(Bot bot) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) { return; @@ -317,9 +313,7 @@ internal static class PluginsCore { } internal static async Task OnBotDisconnected(Bot bot, EResult reason) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) { return; @@ -333,9 +327,7 @@ internal static class PluginsCore { } internal static async Task OnBotFarmingFinished(Bot bot, bool farmedSomething) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) { return; @@ -349,9 +341,7 @@ internal static class PluginsCore { } internal static async Task OnBotFarmingStarted(Bot bot) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) { return; @@ -365,9 +355,7 @@ internal static class PluginsCore { } internal static async Task OnBotFarmingStopped(Bot bot) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) { return; @@ -381,9 +369,7 @@ internal static class PluginsCore { } internal static async Task OnBotFriendRequest(Bot bot, ulong steamID) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((steamID == 0) || !new SteamID(steamID).IsValid) { throw new ArgumentOutOfRangeException(nameof(steamID)); @@ -407,9 +393,7 @@ internal static class PluginsCore { } internal static async Task OnBotInit(Bot bot) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) { return; @@ -423,9 +407,7 @@ internal static class PluginsCore { } internal static async Task OnBotInitModules(Bot bot, IReadOnlyDictionary? additionalConfigProperties = null) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) { return; @@ -439,9 +421,7 @@ internal static class PluginsCore { } internal static async Task OnBotLoggedOn(Bot bot) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) { return; @@ -455,9 +435,7 @@ internal static class PluginsCore { } internal static async Task OnBotMessage(Bot bot, ulong steamID, string message) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { throw new ArgumentOutOfRangeException(nameof(steamID)); @@ -485,13 +463,9 @@ internal static class PluginsCore { } internal static async Task OnBotSteamCallbacksInit(Bot bot, CallbackManager callbackManager) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); - if (callbackManager == null) { - throw new ArgumentNullException(nameof(callbackManager)); - } + ArgumentNullException.ThrowIfNull(callbackManager); if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) { return; @@ -505,9 +479,7 @@ internal static class PluginsCore { } internal static async Task?> OnBotSteamHandlersInit(Bot bot) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) { return null; @@ -527,13 +499,9 @@ internal static class PluginsCore { } internal static async Task OnBotTradeOffer(Bot bot, TradeOffer tradeOffer) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); - if (tradeOffer == null) { - throw new ArgumentNullException(nameof(tradeOffer)); - } + ArgumentNullException.ThrowIfNull(tradeOffer); if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) { return false; @@ -553,9 +521,7 @@ internal static class PluginsCore { } internal static async Task OnBotTradeOfferResults(Bot bot, IReadOnlyCollection tradeResults) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((tradeResults == null) || (tradeResults.Count == 0)) { throw new ArgumentNullException(nameof(tradeResults)); @@ -573,9 +539,7 @@ internal static class PluginsCore { } internal static async Task OnBotUserNotifications(Bot bot, IReadOnlyCollection newNotifications) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((newNotifications == null) || (newNotifications.Count == 0)) { throw new ArgumentNullException(nameof(newNotifications)); @@ -597,13 +561,9 @@ internal static class PluginsCore { throw new ArgumentOutOfRangeException(nameof(currentChangeNumber)); } - if (appChanges == null) { - throw new ArgumentNullException(nameof(appChanges)); - } + ArgumentNullException.ThrowIfNull(appChanges); - if (packageChanges == null) { - throw new ArgumentNullException(nameof(packageChanges)); - } + ArgumentNullException.ThrowIfNull(packageChanges); if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) { return; diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 8e2d8c52b..83e62eb9f 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -445,9 +445,7 @@ internal static class Program { } private static async Task Main(string[] args) { - if (args == null) { - throw new ArgumentNullException(nameof(args)); - } + ArgumentNullException.ThrowIfNull(args); // Initialize await Init(args.Length > 0 ? args : null).ConfigureAwait(false); @@ -460,9 +458,7 @@ internal static class Program { #if !NETFRAMEWORK private static async void OnPosixSignal(PosixSignalContext signal) { - if (signal == null) { - throw new ArgumentNullException(nameof(signal)); - } + ArgumentNullException.ThrowIfNull(signal); switch (signal.Signal) { case PosixSignal.SIGINT: @@ -480,9 +476,7 @@ internal static class Program { private static async void OnProcessExit(object? sender, EventArgs e) => await Shutdown().ConfigureAwait(false); private static async void OnUnhandledException(object? sender, UnhandledExceptionEventArgs e) { - if (e == null) { - throw new ArgumentNullException(nameof(e)); - } + ArgumentNullException.ThrowIfNull(e); if (e.ExceptionObject == null) { throw new ArgumentNullException(nameof(e)); @@ -493,9 +487,7 @@ internal static class Program { } private static async void OnUnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e) { - if (e == null) { - throw new ArgumentNullException(nameof(e)); - } + ArgumentNullException.ThrowIfNull(e); if (e.Exception == null) { throw new ArgumentNullException(nameof(e)); diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index 6f2813da7..998efc3c4 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -1270,9 +1270,7 @@ public sealed class Bot : IAsyncDisposable { } internal async Task IdleGame(Game game) { - if (game == null) { - throw new ArgumentNullException(nameof(game)); - } + ArgumentNullException.ThrowIfNull(game); string? gameName = null; @@ -1709,9 +1707,7 @@ public sealed class Bot : IAsyncDisposable { } internal bool TryImportAuthenticator(MobileAuthenticator authenticator) { - if (authenticator == null) { - throw new ArgumentNullException(nameof(authenticator)); - } + ArgumentNullException.ThrowIfNull(authenticator); if (HasMobileAuthenticator) { return false; @@ -1872,9 +1868,7 @@ public sealed class Bot : IAsyncDisposable { } private HashSet? GetPossiblyCompletedBadgeAppIDs(IDocument badgePage) { - if (badgePage == null) { - throw new ArgumentNullException(nameof(badgePage)); - } + ArgumentNullException.ThrowIfNull(badgePage); // We select badges that are ready to craft, as well as those that are already crafted to a maximum level, as those will not display with a craft button // Level 5 is maximum level for card badges according to https://steamcommunity.com/tradingcards/faq @@ -2211,9 +2205,7 @@ public sealed class Bot : IAsyncDisposable { } private async void OnConnected(SteamClient.ConnectedCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); HeartBeatFailures = 0; ReconnectOnUserInitiated = false; @@ -2335,9 +2327,7 @@ public sealed class Bot : IAsyncDisposable { } private async void OnDisconnected(SteamClient.DisconnectedCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); if (ASF.LoginRateLimitingSemaphore == null) { throw new InvalidOperationException(nameof(ASF.LoginRateLimitingSemaphore)); @@ -2411,9 +2401,7 @@ public sealed class Bot : IAsyncDisposable { } private async void OnFriendsList(SteamFriends.FriendsListCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); if (callback.FriendList == null) { throw new ArgumentNullException(nameof(callback)); @@ -2492,9 +2480,7 @@ public sealed class Bot : IAsyncDisposable { } private async void OnGuestPassList(SteamApps.GuestPassListCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); if (callback.GuestPasses == null) { throw new ArgumentNullException(nameof(callback)); @@ -2514,9 +2500,7 @@ public sealed class Bot : IAsyncDisposable { } private async Task OnIncomingChatMessage(CChatRoom_IncomingChatMessage_Notification notification) { - if (notification == null) { - throw new ArgumentNullException(nameof(notification)); - } + ArgumentNullException.ThrowIfNull(notification); if ((notification.chat_group_id == 0) || (notification.chat_id == 0) || (notification.steamid_sender == 0)) { ArchiLogger.LogNullError($"{nameof(notification.chat_group_id)} || {nameof(notification.chat_id)} || {nameof(notification.steamid_sender)}"); @@ -2556,9 +2540,7 @@ public sealed class Bot : IAsyncDisposable { } private async Task OnIncomingMessage(CFriendMessages_IncomingMessage_Notification notification) { - if (notification == null) { - throw new ArgumentNullException(nameof(notification)); - } + ArgumentNullException.ThrowIfNull(notification); if (notification.steamid_friend == 0) { ArchiLogger.LogNullError(nameof(notification.steamid_friend)); @@ -2614,9 +2596,7 @@ public sealed class Bot : IAsyncDisposable { } private async void OnLicenseList(SteamApps.LicenseListCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); if (callback.LicenseList == null) { throw new ArgumentNullException(nameof(callback)); @@ -2673,9 +2653,7 @@ public sealed class Bot : IAsyncDisposable { } private void OnLoggedOff(SteamUser.LoggedOffCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); LastLogOnResult = callback.Result; @@ -2707,9 +2685,7 @@ public sealed class Bot : IAsyncDisposable { } private async void OnLoggedOn(SteamUser.LoggedOnCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); // Always reset one-time-only access tokens when we get OnLoggedOn() response AuthCode = TwoFactorCode = null; @@ -2935,9 +2911,7 @@ public sealed class Bot : IAsyncDisposable { } private void OnLoginKey(SteamUser.LoginKeyCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); if (string.IsNullOrEmpty(callback.LoginKey)) { throw new ArgumentNullException(nameof(callback)); @@ -2958,9 +2932,7 @@ public sealed class Bot : IAsyncDisposable { } private async void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); string sentryFilePath = GetFilePath(EFileType.SentryFile); @@ -3021,9 +2993,7 @@ public sealed class Bot : IAsyncDisposable { } private void OnPersonaState(SteamFriends.PersonaStateCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); if (callback.FriendID != SteamID) { return; @@ -3050,9 +3020,7 @@ public sealed class Bot : IAsyncDisposable { } private async void OnPlayingSessionState(ArchiHandler.PlayingSessionStateCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); if (callback.PlayingBlocked == PlayingBlocked) { return; // No status update, we're not interested @@ -3065,9 +3033,7 @@ public sealed class Bot : IAsyncDisposable { private async void OnSendItemsTimer(object? state = null) => await Actions.SendInventory(filterFunction: item => BotConfig.LootableTypes.Contains(item.Type)).ConfigureAwait(false); private async void OnServiceMethod(SteamUnifiedMessages.ServiceMethodNotification notification) { - if (notification == null) { - throw new ArgumentNullException(nameof(notification)); - } + ArgumentNullException.ThrowIfNull(notification); switch (notification.MethodName) { case "ChatRoomClient.NotifyIncomingChatMessage#1": @@ -3082,9 +3048,7 @@ public sealed class Bot : IAsyncDisposable { } private async void OnSharedLibraryLockStatus(ArchiHandler.SharedLibraryLockStatusCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); // Ignore no status updates if (LibraryLocked) { @@ -3105,9 +3069,7 @@ public sealed class Bot : IAsyncDisposable { } private void OnUserNotifications(UserNotificationsCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); if (callback.Notifications == null) { throw new ArgumentNullException(nameof(callback)); @@ -3158,17 +3120,13 @@ public sealed class Bot : IAsyncDisposable { } private void OnVanityURLChangedCallback(SteamUser.VanityURLChangedCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); ArchiWebHandler.OnVanityURLChanged(callback.VanityURL); } private void OnWalletUpdate(SteamUser.WalletInfoCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); WalletBalance = callback.LongBalance; WalletCurrency = callback.Currency; @@ -3492,9 +3450,7 @@ public sealed class Bot : IAsyncDisposable { } private (bool IsSteamParentalEnabled, string? SteamParentalCode) ValidateSteamParental(ParentalSettings settings, string? steamParentalCode = null) { - if (settings == null) { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (!settings.is_enabled) { return (false, null); diff --git a/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs b/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs index c911d2f86..36805f7b2 100644 --- a/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs +++ b/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs @@ -394,13 +394,9 @@ public sealed class CardsFarmer : IAsyncDisposable { } private async Task CheckPage(IDocument htmlDocument, ISet parsedAppIDs) { - if (htmlDocument == null) { - throw new ArgumentNullException(nameof(htmlDocument)); - } + ArgumentNullException.ThrowIfNull(htmlDocument); - if (parsedAppIDs == null) { - throw new ArgumentNullException(nameof(parsedAppIDs)); - } + ArgumentNullException.ThrowIfNull(parsedAppIDs); IEnumerable htmlNodes = htmlDocument.SelectNodes("//div[@class='badge_row_inner']"); @@ -716,9 +712,7 @@ public sealed class CardsFarmer : IAsyncDisposable { throw new ArgumentOutOfRangeException(nameof(page)); } - if (parsedAppIDs == null) { - throw new ArgumentNullException(nameof(parsedAppIDs)); - } + ArgumentNullException.ThrowIfNull(parsedAppIDs); using IDocument? htmlDocument = await Bot.ArchiWebHandler.GetBadgePage(page).ConfigureAwait(false); @@ -829,9 +823,7 @@ public sealed class CardsFarmer : IAsyncDisposable { } private async Task FarmCards(Game game) { - if (game == null) { - throw new ArgumentNullException(nameof(game)); - } + ArgumentNullException.ThrowIfNull(game); if (game.AppID != game.PlayableAppID) { Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningIdlingGameMismatch, game.AppID, game.GameName, game.PlayableAppID)); @@ -936,9 +928,7 @@ public sealed class CardsFarmer : IAsyncDisposable { } private async Task FarmSolo(Game game) { - if (game == null) { - throw new ArgumentNullException(nameof(game)); - } + ArgumentNullException.ThrowIfNull(game); CurrentGamesFarming.Add(game); @@ -1076,9 +1066,7 @@ public sealed class CardsFarmer : IAsyncDisposable { } private async Task IsPlayableGame(Game game) { - if (game == null) { - throw new ArgumentNullException(nameof(game)); - } + ArgumentNullException.ThrowIfNull(game); (uint playableAppID, DateTime ignoredUntil, bool ignoredGlobally) = await Bot.GetAppDataForIdling(game.AppID, game.HoursPlayed).ConfigureAwait(false); @@ -1097,9 +1085,7 @@ public sealed class CardsFarmer : IAsyncDisposable { } private async Task ShouldFarm(Game game) { - if (game == null) { - throw new ArgumentNullException(nameof(game)); - } + ArgumentNullException.ThrowIfNull(game); ushort? cardsRemaining = await GetCardsRemaining(game.AppID).ConfigureAwait(false); diff --git a/ArchiSteamFarm/Steam/Exchange/Trading.cs b/ArchiSteamFarm/Steam/Exchange/Trading.cs index bc0f2a262..354de4a0d 100644 --- a/ArchiSteamFarm/Steam/Exchange/Trading.cs +++ b/ArchiSteamFarm/Steam/Exchange/Trading.cs @@ -292,13 +292,9 @@ public sealed class Trading : IDisposable { } internal static bool IsEmptyForMatching(IReadOnlyDictionary<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity), Dictionary> fullState, IReadOnlyDictionary<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity), Dictionary> tradableState) { - if (fullState == null) { - throw new ArgumentNullException(nameof(fullState)); - } + ArgumentNullException.ThrowIfNull(fullState); - if (tradableState == null) { - throw new ArgumentNullException(nameof(tradableState)); - } + ArgumentNullException.ThrowIfNull(tradableState); foreach (((uint RealAppID, Asset.EType Type, Asset.ERarity Rarity) set, IReadOnlyDictionary state) in tradableState) { if (!fullState.TryGetValue(set, out Dictionary? fullSet) || (fullSet.Count == 0)) { @@ -315,13 +311,9 @@ public sealed class Trading : IDisposable { } internal static bool IsEmptyForMatching(IReadOnlyDictionary fullSet, IReadOnlyDictionary tradableSet) { - if (fullSet == null) { - throw new ArgumentNullException(nameof(fullSet)); - } + ArgumentNullException.ThrowIfNull(fullSet); - if (tradableSet == null) { - throw new ArgumentNullException(nameof(tradableSet)); - } + ArgumentNullException.ThrowIfNull(tradableSet); foreach ((ulong classID, uint amount) in tradableSet) { switch (amount) { @@ -446,9 +438,7 @@ public sealed class Trading : IDisposable { } private async Task<(ParseTradeResult? TradeResult, bool RequiresMobileConfirmation)> ParseTrade(TradeOffer tradeOffer) { - if (tradeOffer == null) { - throw new ArgumentNullException(nameof(tradeOffer)); - } + ArgumentNullException.ThrowIfNull(tradeOffer); if (tradeOffer.State != ETradeOfferState.Active) { Bot.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, tradeOffer.State)); @@ -527,9 +517,7 @@ public sealed class Trading : IDisposable { } private async Task ShouldAcceptTrade(TradeOffer tradeOffer) { - if (tradeOffer == null) { - throw new ArgumentNullException(nameof(tradeOffer)); - } + ArgumentNullException.ThrowIfNull(tradeOffer); if (ASF.GlobalConfig == null) { throw new InvalidOperationException(nameof(ASF.GlobalConfig)); diff --git a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs index d04c79eef..d1912f743 100644 --- a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs +++ b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs @@ -48,9 +48,7 @@ public sealed class ArchiHandler : ClientMsgHandler { internal DateTime LastPacketReceived { get; private set; } internal ArchiHandler(ArchiLogger archiLogger, SteamUnifiedMessages steamUnifiedMessages) { - if (steamUnifiedMessages == null) { - throw new ArgumentNullException(nameof(steamUnifiedMessages)); - } + ArgumentNullException.ThrowIfNull(steamUnifiedMessages); ArchiLogger = archiLogger ?? throw new ArgumentNullException(nameof(archiLogger)); UnifiedChatRoomService = steamUnifiedMessages.CreateService(); @@ -132,9 +130,7 @@ public sealed class ArchiHandler : ClientMsgHandler { } public override void HandleMsg(IPacketMsg packetMsg) { - if (packetMsg == null) { - throw new ArgumentNullException(nameof(packetMsg)); - } + ArgumentNullException.ThrowIfNull(packetMsg); if (Client == null) { throw new InvalidOperationException(nameof(Client)); @@ -499,9 +495,7 @@ public sealed class ArchiHandler : ClientMsgHandler { } internal async Task PlayGames(IReadOnlyCollection gameIDs, string? gameName = null) { - if (gameIDs == null) { - throw new ArgumentNullException(nameof(gameIDs)); - } + ArgumentNullException.ThrowIfNull(gameIDs); if (Client == null) { throw new InvalidOperationException(nameof(Client)); @@ -777,9 +771,7 @@ public sealed class ArchiHandler : ClientMsgHandler { throw new ArgumentNullException(nameof(jobID)); } - if (msg == null) { - throw new ArgumentNullException(nameof(msg)); - } + ArgumentNullException.ThrowIfNull(msg); JobID = jobID; PlayingBlocked = msg.playing_blocked; @@ -794,9 +786,7 @@ public sealed class ArchiHandler : ClientMsgHandler { throw new ArgumentNullException(nameof(jobID)); } - if (msg == null) { - throw new ArgumentNullException(nameof(msg)); - } + ArgumentNullException.ThrowIfNull(msg); JobID = jobID; diff --git a/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs b/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs index 2ffdbaa4f..50c2f6041 100644 --- a/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs +++ b/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs @@ -1163,9 +1163,7 @@ public sealed class ArchiWebHandler : IDisposable { throw new ArgumentNullException(nameof(service)); } - if (function == null) { - throw new ArgumentNullException(nameof(function)); - } + ArgumentNullException.ThrowIfNull(function); if (ASF.RateLimitingSemaphore == null) { throw new InvalidOperationException(nameof(ASF.RateLimitingSemaphore)); @@ -1325,9 +1323,7 @@ public sealed class ArchiWebHandler : IDisposable { } internal async Task ChangePrivacySettings(UserPrivacy userPrivacy) { - if (userPrivacy == null) { - throw new ArgumentNullException(nameof(userPrivacy)); - } + ArgumentNullException.ThrowIfNull(userPrivacy); string? profileURL = await GetAbsoluteProfileURL().ConfigureAwait(false); @@ -2485,17 +2481,13 @@ public sealed class ArchiWebHandler : IDisposable { } private static bool ParseItems(IReadOnlyDictionary<(uint AppID, ulong ClassID, ulong InstanceID), InventoryResponse.Description> descriptions, IReadOnlyCollection input, ICollection output) { - if (descriptions == null) { - throw new ArgumentNullException(nameof(descriptions)); - } + ArgumentNullException.ThrowIfNull(descriptions); if ((input == null) || (input.Count == 0)) { throw new ArgumentNullException(nameof(input)); } - if (output == null) { - throw new ArgumentNullException(nameof(output)); - } + ArgumentNullException.ThrowIfNull(output); foreach (KeyValue item in input) { uint appID = item["appid"].AsUnsignedInteger(); diff --git a/ArchiSteamFarm/Steam/Integration/CMsgs/CMsgClientAcknowledgeClanInvite.cs b/ArchiSteamFarm/Steam/Integration/CMsgs/CMsgClientAcknowledgeClanInvite.cs index 1b8f82cf6..6825383b9 100644 --- a/ArchiSteamFarm/Steam/Integration/CMsgs/CMsgClientAcknowledgeClanInvite.cs +++ b/ArchiSteamFarm/Steam/Integration/CMsgs/CMsgClientAcknowledgeClanInvite.cs @@ -32,9 +32,7 @@ internal sealed class CMsgClientAcknowledgeClanInvite : ISteamSerializableMessag internal ulong ClanID { private get; set; } void ISteamSerializable.Deserialize(Stream stream) { - if (stream == null) { - throw new ArgumentNullException(nameof(stream)); - } + ArgumentNullException.ThrowIfNull(stream); using BinaryReader binaryReader = new(stream, Encoding.UTF8, true); @@ -45,9 +43,7 @@ internal sealed class CMsgClientAcknowledgeClanInvite : ISteamSerializableMessag EMsg ISteamSerializableMessage.GetEMsg() => EMsg.ClientAcknowledgeClanInvite; void ISteamSerializable.Serialize(Stream stream) { - if (stream == null) { - throw new ArgumentNullException(nameof(stream)); - } + ArgumentNullException.ThrowIfNull(stream); using BinaryWriter binaryWriter = new(stream, Encoding.UTF8, true); diff --git a/ArchiSteamFarm/Steam/Integration/Callbacks/UserNotificationsCallback.cs b/ArchiSteamFarm/Steam/Integration/Callbacks/UserNotificationsCallback.cs index a53c6ebf2..567e6dddb 100644 --- a/ArchiSteamFarm/Steam/Integration/Callbacks/UserNotificationsCallback.cs +++ b/ArchiSteamFarm/Steam/Integration/Callbacks/UserNotificationsCallback.cs @@ -38,9 +38,7 @@ public sealed class UserNotificationsCallback : CallbackMsg { throw new ArgumentNullException(nameof(jobID)); } - if (msg == null) { - throw new ArgumentNullException(nameof(msg)); - } + ArgumentNullException.ThrowIfNull(msg); JobID = jobID; @@ -82,9 +80,7 @@ public sealed class UserNotificationsCallback : CallbackMsg { throw new ArgumentNullException(nameof(jobID)); } - if (msg == null) { - throw new ArgumentNullException(nameof(msg)); - } + ArgumentNullException.ThrowIfNull(msg); JobID = jobID; Notifications = new Dictionary(1) { { EUserNotification.Items, msg.count_new_items } }; @@ -95,9 +91,7 @@ public sealed class UserNotificationsCallback : CallbackMsg { throw new ArgumentNullException(nameof(jobID)); } - if (msg == null) { - throw new ArgumentNullException(nameof(msg)); - } + ArgumentNullException.ThrowIfNull(msg); JobID = jobID; Notifications = new Dictionary(1) { { EUserNotification.Comments, msg.count_new_comments + msg.count_new_comments_owner + msg.count_new_comments_subscriptions } }; diff --git a/ArchiSteamFarm/Steam/Integration/SteamUtilities.cs b/ArchiSteamFarm/Steam/Integration/SteamUtilities.cs index 17bdb9647..9a927edcb 100644 --- a/ArchiSteamFarm/Steam/Integration/SteamUtilities.cs +++ b/ArchiSteamFarm/Steam/Integration/SteamUtilities.cs @@ -29,9 +29,7 @@ namespace ArchiSteamFarm.Steam.Integration; internal static class SteamUtilities { internal static Dictionary? ParseItems(this SteamApps.PurchaseResponseCallback callback) { - if (callback == null) { - throw new ArgumentNullException(nameof(callback)); - } + ArgumentNullException.ThrowIfNull(callback); List lineItems = callback.PurchaseReceiptInfo["lineitems"].Children; diff --git a/ArchiSteamFarm/Steam/Interaction/Actions.cs b/ArchiSteamFarm/Steam/Interaction/Actions.cs index f2103de2c..cc2ede197 100644 --- a/ArchiSteamFarm/Steam/Interaction/Actions.cs +++ b/ArchiSteamFarm/Steam/Interaction/Actions.cs @@ -223,9 +223,7 @@ public sealed class Actions : IAsyncDisposable { [PublicAPI] public async Task<(bool Success, string Message)> Play(IReadOnlyCollection gameIDs, string? gameName = null) { - if (gameIDs == null) { - throw new ArgumentNullException(nameof(gameIDs)); - } + ArgumentNullException.ThrowIfNull(gameIDs); if (!Bot.IsConnectedAndLoggedOn) { return (false, Strings.BotNotConnected); diff --git a/ArchiSteamFarm/Steam/Interaction/Commands.cs b/ArchiSteamFarm/Steam/Interaction/Commands.cs index 809036940..6f17f2a3a 100644 --- a/ArchiSteamFarm/Steam/Interaction/Commands.cs +++ b/ArchiSteamFarm/Steam/Interaction/Commands.cs @@ -869,9 +869,7 @@ public sealed class Commands { throw new ArgumentOutOfRangeException(nameof(contextID)); } - if (targetBot == null) { - throw new ArgumentNullException(nameof(targetBot)); - } + ArgumentNullException.ThrowIfNull(targetBot); if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { return null; @@ -2131,9 +2129,7 @@ public sealed class Commands { throw new ArgumentOutOfRangeException(nameof(steamID)); } - if (gameIDs == null) { - throw new ArgumentNullException(nameof(gameIDs)); - } + ArgumentNullException.ThrowIfNull(gameIDs); if (gameIDs.Count > ArchiHandler.MaxGamesPlayedConcurrently) { throw new ArgumentOutOfRangeException(nameof(gameIDs)); @@ -3176,9 +3172,7 @@ public sealed class Commands { throw new ArgumentNullException(nameof(realAppIDs)); } - if (targetBot == null) { - throw new ArgumentNullException(nameof(targetBot)); - } + ArgumentNullException.ThrowIfNull(targetBot); if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { return null; diff --git a/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs b/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs index 7722974be..5280a2014 100644 --- a/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs +++ b/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs @@ -36,9 +36,7 @@ internal sealed class InMemoryServerListProvider : IServerListProvider { public Task> FetchServerListAsync() => Task.FromResult(ServerRecords.Where(static server => !string.IsNullOrEmpty(server.Host) && (server.Port > 0) && (server.ProtocolTypes > 0)).Select(static server => ServerRecord.CreateServer(server.Host, server.Port, server.ProtocolTypes))); public Task UpdateServerListAsync(IEnumerable endpoints) { - if (endpoints == null) { - throw new ArgumentNullException(nameof(endpoints)); - } + ArgumentNullException.ThrowIfNull(endpoints); HashSet newServerRecords = endpoints.Select(static endpoint => new ServerRecordEndPoint(endpoint.GetHost(), (ushort) endpoint.GetPort(), endpoint.ProtocolTypes)).ToHashSet(); diff --git a/ArchiSteamFarm/Steam/Storage/BotConfig.cs b/ArchiSteamFarm/Steam/Storage/BotConfig.cs index 53426ec2f..ce083e22e 100644 --- a/ArchiSteamFarm/Steam/Storage/BotConfig.cs +++ b/ArchiSteamFarm/Steam/Storage/BotConfig.cs @@ -402,9 +402,7 @@ public sealed class BotConfig { throw new ArgumentNullException(nameof(filePath)); } - if (botConfig == null) { - throw new ArgumentNullException(nameof(botConfig)); - } + ArgumentNullException.ThrowIfNull(botConfig); string json = JsonConvert.SerializeObject(botConfig, Formatting.Indented); diff --git a/ArchiSteamFarm/Storage/GlobalConfig.cs b/ArchiSteamFarm/Storage/GlobalConfig.cs index cb6803d1d..0fc7dc3bc 100644 --- a/ArchiSteamFarm/Storage/GlobalConfig.cs +++ b/ArchiSteamFarm/Storage/GlobalConfig.cs @@ -541,9 +541,7 @@ public sealed class GlobalConfig { throw new ArgumentNullException(nameof(filePath)); } - if (globalConfig == null) { - throw new ArgumentNullException(nameof(globalConfig)); - } + ArgumentNullException.ThrowIfNull(globalConfig); string json = JsonConvert.SerializeObject(globalConfig, Formatting.Indented); diff --git a/ArchiSteamFarm/Storage/GlobalDatabase.cs b/ArchiSteamFarm/Storage/GlobalDatabase.cs index d7d255960..252ccb972 100644 --- a/ArchiSteamFarm/Storage/GlobalDatabase.cs +++ b/ArchiSteamFarm/Storage/GlobalDatabase.cs @@ -137,9 +137,7 @@ public sealed class GlobalDatabase : SerializableFile { throw new ArgumentNullException(nameof(key)); } - if (value == null) { - throw new ArgumentNullException(nameof(value)); - } + ArgumentNullException.ThrowIfNull(value); if (value.Type == JTokenType.Null) { DeleteFromJsonStorage(key); @@ -233,9 +231,7 @@ public sealed class GlobalDatabase : SerializableFile { throw new ArgumentOutOfRangeException(nameof(appID)); } - if (packageIDs == null) { - throw new ArgumentNullException(nameof(packageIDs)); - } + ArgumentNullException.ThrowIfNull(packageIDs); HashSet result = new(); @@ -300,9 +296,7 @@ public sealed class GlobalDatabase : SerializableFile { } internal async Task RefreshPackages(Bot bot, IReadOnlyDictionary packages) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); - } + ArgumentNullException.ThrowIfNull(bot); if ((packages == null) || (packages.Count == 0)) { throw new ArgumentNullException(nameof(packages)); diff --git a/ArchiSteamFarm/Web/Responses/BasicResponse.cs b/ArchiSteamFarm/Web/Responses/BasicResponse.cs index ab85a08ba..a2f5eaea4 100644 --- a/ArchiSteamFarm/Web/Responses/BasicResponse.cs +++ b/ArchiSteamFarm/Web/Responses/BasicResponse.cs @@ -33,18 +33,14 @@ public class BasicResponse { internal readonly Uri FinalUri; internal BasicResponse(HttpResponseMessage httpResponseMessage) { - if (httpResponseMessage == null) { - throw new ArgumentNullException(nameof(httpResponseMessage)); - } + ArgumentNullException.ThrowIfNull(httpResponseMessage); FinalUri = httpResponseMessage.Headers.Location ?? httpResponseMessage.RequestMessage?.RequestUri ?? throw new InvalidOperationException(); StatusCode = httpResponseMessage.StatusCode; } internal BasicResponse(BasicResponse basicResponse) { - if (basicResponse == null) { - throw new ArgumentNullException(nameof(basicResponse)); - } + ArgumentNullException.ThrowIfNull(basicResponse); FinalUri = basicResponse.FinalUri; StatusCode = basicResponse.StatusCode; diff --git a/ArchiSteamFarm/Web/Responses/BinaryResponse.cs b/ArchiSteamFarm/Web/Responses/BinaryResponse.cs index 272dfd95e..4eb3b5618 100644 --- a/ArchiSteamFarm/Web/Responses/BinaryResponse.cs +++ b/ArchiSteamFarm/Web/Responses/BinaryResponse.cs @@ -32,9 +32,7 @@ public sealed class BinaryResponse : BasicResponse { private readonly byte[] Bytes; public BinaryResponse(BasicResponse basicResponse, byte[] bytes) : base(basicResponse) { - if (basicResponse == null) { - throw new ArgumentNullException(nameof(basicResponse)); - } + ArgumentNullException.ThrowIfNull(basicResponse); Bytes = bytes ?? throw new ArgumentNullException(nameof(bytes)); } diff --git a/ArchiSteamFarm/Web/Responses/HtmlDocumentResponse.cs b/ArchiSteamFarm/Web/Responses/HtmlDocumentResponse.cs index 71c03b7a7..98ae84b62 100644 --- a/ArchiSteamFarm/Web/Responses/HtmlDocumentResponse.cs +++ b/ArchiSteamFarm/Web/Responses/HtmlDocumentResponse.cs @@ -33,9 +33,7 @@ public sealed class HtmlDocumentResponse : BasicResponse, IDisposable { public IDocument Content { get; } private HtmlDocumentResponse(BasicResponse basicResponse, IDocument content) : base(basicResponse) { - if (basicResponse == null) { - throw new ArgumentNullException(nameof(basicResponse)); - } + ArgumentNullException.ThrowIfNull(basicResponse); Content = content ?? throw new ArgumentNullException(nameof(content)); } @@ -44,9 +42,7 @@ public sealed class HtmlDocumentResponse : BasicResponse, IDisposable { [PublicAPI] public static async Task Create(StreamResponse streamResponse) { - if (streamResponse == null) { - throw new ArgumentNullException(nameof(streamResponse)); - } + ArgumentNullException.ThrowIfNull(streamResponse); IBrowsingContext context = BrowsingContext.New(); diff --git a/ArchiSteamFarm/Web/Responses/ObjectResponse.cs b/ArchiSteamFarm/Web/Responses/ObjectResponse.cs index 60cc93589..afdedb027 100644 --- a/ArchiSteamFarm/Web/Responses/ObjectResponse.cs +++ b/ArchiSteamFarm/Web/Responses/ObjectResponse.cs @@ -29,9 +29,7 @@ public sealed class ObjectResponse : BasicResponse { public T Content { get; } public ObjectResponse(BasicResponse basicResponse, T content) : base(basicResponse) { - if (basicResponse == null) { - throw new ArgumentNullException(nameof(basicResponse)); - } + ArgumentNullException.ThrowIfNull(basicResponse); Content = content ?? throw new ArgumentNullException(nameof(content)); }