From 7f7d74e9c9643d3fad0cc141fad2c2f1d1a39aa3 Mon Sep 17 00:00:00 2001 From: "TILDE\\guntars.puzulis" Date: Wed, 21 Aug 2024 11:26:56 +0300 Subject: [PATCH] Add additional option validation --- Tilde.Translation/Translator.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Tilde.Translation/Translator.cs b/Tilde.Translation/Translator.cs index 6a41ed2..e4eb774 100644 --- a/Tilde.Translation/Translator.cs +++ b/Tilde.Translation/Translator.cs @@ -39,14 +39,17 @@ public Translator(string apiKey, TranslatorOptions? options = null) { options ??= new TranslatorOptions(); - if (string.IsNullOrWhiteSpace(options.AppInfo?.AppVersion)) + if (options.AppInfo != null) { - throw new ArgumentNullException($"{nameof(options)}.{nameof(options.AppInfo)}.{nameof(options.AppInfo.AppVersion)}"); - } + if (string.IsNullOrWhiteSpace(options.AppInfo.AppVersion)) + { + throw new ArgumentNullException($"{nameof(options)}.{nameof(options.AppInfo)}.{nameof(options.AppInfo.AppVersion)}"); + } - if (string.IsNullOrWhiteSpace(options.AppInfo?.AppName)) - { - throw new ArgumentNullException($"{nameof(options)}.{nameof(options.AppInfo)}.{nameof(options.AppInfo.AppName)}"); + if (string.IsNullOrWhiteSpace(options.AppInfo.AppName)) + { + throw new ArgumentNullException($"{nameof(options)}.{nameof(options.AppInfo)}.{nameof(options.AppInfo.AppName)}"); + } } if (apiKey == null)