Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add resource value validation for DefaultFormatter #588

Merged
merged 5 commits into from
Dec 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/Humanizer/Localisation/Formatters/DefaultFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,36 @@ private string GetResourceForTimeSpan(TimeUnit unit, int count)
}

/// <summary>
///
/// Formats the specified resource key.
/// </summary>
/// <param name="resourceKey"></param>
/// <param name="resourceKey">The resource key.</param>
/// <returns></returns>
/// <exception cref="ArgumentException">If the resource not exists on the specified culture.</exception>
protected virtual string Format(string resourceKey)
{
return Resources.GetResource(GetResourceKey(resourceKey), _culture);
var resourceString = Resources.GetResource(GetResourceKey(resourceKey), _culture);

if (string.IsNullOrEmpty(resourceString))
throw new ArgumentException($"The resource object with key '{resourceKey}' was not found", nameof(resourceKey));

return resourceString;
}

/// <summary>
///
/// Formats the specified resource key.
/// </summary>
/// <param name="resourceKey"></param>
/// <param name="number"></param>
/// <param name="resourceKey">The resource key.</param>
/// <param name="number">The number.</param>
/// <returns></returns>
/// <exception cref="ArgumentException">If the resource not exists on the specified culture.</exception>
protected virtual string Format(string resourceKey, int number)
{
return Resources.GetResource(GetResourceKey(resourceKey, number), _culture).FormatWith(number);
var resourceString = Resources.GetResource(GetResourceKey(resourceKey, number), _culture);

if (string.IsNullOrEmpty(resourceString))
throw new ArgumentException($"The resource object with key '{resourceKey}' was not found", nameof(resourceKey));

return resourceString.FormatWith(number);
}

/// <summary>
Expand Down