Skip to content

Commit

Permalink
Merge pull request #5 from tilde-nlp/fix/option_validation
Browse files Browse the repository at this point in the history
Add option validation
  • Loading branch information
gunpuz authored Aug 21, 2024
2 parents e25f329 + 7f7d74e commit c515b3c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Tilde.Translation/AppInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public class AppInfo
/// <summary>
/// Application name where this library will be used
/// </summary>
public string? AppName { get; set; }
public string AppName { get; set; }

Check warning on line 20 in Tilde.Translation/AppInfo.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'AppName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 20 in Tilde.Translation/AppInfo.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'AppName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 20 in Tilde.Translation/AppInfo.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'AppName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 20 in Tilde.Translation/AppInfo.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'AppName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

/// <summary>
/// Version of application where this library will be used
/// </summary>
public string? AppVersion { get; set; }
public string AppVersion { get; set; }

Check warning on line 25 in Tilde.Translation/AppInfo.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'AppVersion' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 25 in Tilde.Translation/AppInfo.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'AppVersion' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 25 in Tilde.Translation/AppInfo.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'AppVersion' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

/// <summary>
/// Origin which requests machine translation
Expand Down
2 changes: 1 addition & 1 deletion Tilde.Translation/Tilde.Translation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description>Official dotnet library for the Tilde translation API</Description>
<PackageTags>tilde;translation;translator;translate;api;i18n;language;</PackageTags>
<!-- Change only <Version> tag, other tags will be autogenerated on build -->
<Version>1.0.10.0</Version>
<Version>1.0.11.0</Version>
<TargetFrameworks>net6.0;net7.0;net8.0;netstandard2.0;netstandard2.1;net462;net472;net48;net481;</TargetFrameworks>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
13 changes: 13 additions & 0 deletions Tilde.Translation/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ public Translator(string apiKey, TranslatorOptions? options = null)
{
options ??= new TranslatorOptions();

if (options.AppInfo != null)
{
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 (apiKey == null)
{
throw new ArgumentNullException(nameof(apiKey));
Expand Down

0 comments on commit c515b3c

Please sign in to comment.