Skip to content

Commit

Permalink
Merge pull request #16 from stevenvolckaert/vNext
Browse files Browse the repository at this point in the history
Merging vNext into master
  • Loading branch information
stevenvolckaert committed Aug 27, 2017
2 parents 73d36c2 + 4eec674 commit 900bb69
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 103 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1.1.0-{build}
version: 1.1.1-{build}
build:
verbosity: minimal
configuration:
Expand Down
53 changes: 37 additions & 16 deletions src/StevenVolckaert.Core/Globalization/CultureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// <summary>
/// Manages cultures of an application.
/// </summary>
public class CultureManager
public class CultureManager : ICultureManager
{
private string _currentCultureName;
/// <summary>
Expand Down Expand Up @@ -147,16 +147,19 @@ public CultureManager(string defaultCultureName, params string[] supportedCultur
: _supportedCultures.First().Key;

_currentCultureName = SetDefaultCulture();
_supportedCultures = _supportedCultures.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
_supportedCultures =
_supportedCultures.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
}

/// <summary>
/// Returns an instance of the <see cref="CultureInfo"/> class based on the culture specified by name,
/// or <c>null</c> if the culture is not supported by the current operating system.
/// Returns an instance of the <see cref="CultureInfo"/> class based on the culture specified by
/// name, or <c>null</c> if the culture is not supported by the current operating system.
/// </summary>
/// <param name="cultureName">The name of a culture.</param>
/// <exception cref="ArgumentNullException"><paramref name="cultureName"/> is <c>null</c>.</exception>
public static CultureInfo GetCultureInfo(string cultureName)
/// <exception cref="ArgumentNullException">
/// <paramref name="cultureName"/> is <c>null</c>.
/// </exception>
public CultureInfo GetCultureInfo(string cultureName)
{
try
{
Expand All @@ -165,7 +168,11 @@ public static CultureInfo GetCultureInfo(string cultureName)
catch (ArgumentNullException)
{
Debug.WriteLine(
message: string.Format(CultureInfo.CurrentCulture, Resources.ValueNull, nameof(cultureName)),
message: string.Format(
CultureInfo.CurrentCulture,
Resources.ValueNull,
nameof(cultureName)
),
callerMemberName: nameof(GetCultureInfo)
);
return null;
Expand All @@ -177,7 +184,11 @@ public static CultureInfo GetCultureInfo(string cultureName)
#endif
{
Debug.WriteLine(
message: string.Format(CultureInfo.CurrentCulture, Resources.IllegalCultureName, cultureName),
message: string.Format(
CultureInfo.CurrentCulture,
Resources.IllegalCultureName,
cultureName
),
callerMemberName: nameof(GetCultureInfo)
);
return null;
Expand All @@ -187,9 +198,13 @@ public static CultureInfo GetCultureInfo(string cultureName)
/// <summary>
/// Convert a given culture name to the name of it's associated neutral culture.
/// </summary>
/// <param name="cultureName">The name of the culture, representing a specific or neutral culture.</param>
/// <returns>The name of the neutral culture, or <c>null</c> if the culture is not supported.</returns>
public static string GetNeutralCultureName(string cultureName)
/// <param name="cultureName">
/// The name of the culture, representing a specific or neutral culture.
/// </param>
/// <returns>
/// The name of the neutral culture, or <c>null</c> if the culture is not supported.
/// </returns>
public string GetNeutralCultureName(string cultureName)
{
if (cultureName.IsNullOrWhiteSpace())
return null;
Expand All @@ -209,7 +224,9 @@ public static string GetNeutralCultureName(string cultureName)
/// Returns a value that indicates whether a given culture, or its associated neutral culture,
/// is supported by this culture manager.
/// </summary>
/// <param name="cultureName">The name of the culture, representing a specific or neutral culture.</param>
/// <param name="cultureName">
/// The name of the culture, representing a specific or neutral culture.
/// </param>
public bool IsCultureSupported(string cultureName)
{
if (IsSpecificCultureSupported(cultureName))
Expand Down Expand Up @@ -248,11 +265,13 @@ public bool IsCultureSelected(string cultureName)
/// Sets the application's current culture.
/// If the given culture is not supported, the manager's default culture is selected.
/// <para>
/// If a given specific culture is not supported, its associated neutral culture is selected
/// (if it exists).
/// If a given specific culture is not supported, its associated neutral culture is selected
/// (if it exists).
/// </para>
/// </summary>
/// <param name="cultureName">The name of the culture, representing a specific or neutral culture.</param>
/// <param name="cultureName">
/// The name of the culture, representing a specific or neutral culture.
/// </param>
/// <returns>The name of the manager's culture when the operation finishes.</returns>
/// <exception cref="ArgumentException">
/// <paramref name="cultureName"/> is <c>null</c>, empty, or white space.
Expand All @@ -275,7 +294,9 @@ public string SetCulture(string cultureName)
/// </summary>
/// <param name="cultureNames">An array that contains zero or more culture names.</param>
/// <returns>The name of the manager's culture when the operation finishes.</returns>
/// <exception cref="ArgumentNullException"><paramref name="cultureNames"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException">
/// <paramref name="cultureNames"/> is <c>null</c>.
/// </exception>
public string SetCulture(params string[] cultureNames)
{
if (cultureNames == null)
Expand Down
118 changes: 118 additions & 0 deletions src/StevenVolckaert.Core/Globalization/ICultureManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
namespace StevenVolckaert.Globalization
{
using System;
using System.Collections.Generic;
using System.Globalization;

/// <summary>
/// Manages cultures of an application.
/// </summary>
public interface ICultureManager
{
/// <summary>
/// Gets the manager's current culture.
/// </summary>
CultureInfo CurrentCulture { get; }
/// <summary>
/// Gets or sets the name of the current culture in the format
/// "&lt;languagecode2&gt;-&lt;country/regioncode2&gt;".
/// </summary>
/// <returns>
/// The current culture name in the format "&lt;languagecode2&gt;-&lt;country/regioncode2&gt;",
/// where "&lt;languagecode2&gt;" is a lowercase two-letter code derived from ISO 639-1
/// and "&lt;country/regioncode2&gt;" is an uppercase two-letter code derived from ISO 3166.
///</returns>
string CurrentCultureName { get; set; }
/// <summary>
/// Gets the name of the manager's default culture.
/// </summary>
string DefaultCultureName { get; }
/// <summary>
/// Gets a dictionary of cultures that are supported by this culture manager.
/// </summary>
Dictionary<string, CultureInfo> SupportedCultures { get; }
/// <summary>
/// Occurs when the manager's culture has changed.
/// </summary>
event EventHandler<CurrentCultureChangedEventArgs> CurrentCultureChanged;
/// <summary>
/// Returns an instance of the <see cref="CultureInfo"/> class based on the culture specified by
/// name, or <c>null</c> if the culture is not supported by the current operating system.
/// </summary>
/// <param name="cultureName">The name of a culture.</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="cultureName"/> is <c>null</c>.
/// </exception>
CultureInfo GetCultureInfo(string cultureName);
/// <summary>
/// Convert a given culture name to the name of it's associated neutral culture.
/// </summary>
/// <param name="cultureName">
/// The name of the culture, representing a specific or neutral culture.
/// </param>
/// <returns>
/// The name of the neutral culture, or <c>null</c> if the culture is not supported.
/// </returns>
string GetNeutralCultureName(string cultureName);
/// <summary>
/// Returns a value that indicates whether a given culture, or it's associated neutral culture,
/// is currently selected.
/// </summary>
/// <param name="cultureName">The name of the culture.</param>
bool IsCultureSelected(string cultureName);
/// <summary>
/// Returns a value that indicates whether a given culture, or its associated neutral culture,
/// is supported by this culture manager.
/// </summary>
/// <param name="cultureName">
/// The name of the culture, representing a specific or neutral culture.
/// </param>
bool IsCultureSupported(string cultureName);
/// <summary>
/// Returns a value that indicates whether a given specific culture is supported
/// by this culture manager.
/// </summary>
/// <param name="cultureName">The name of the culture.</param>
/// <returns><c>true</c> if the culture is supported, <c>false</c> otherwise.</returns>
bool IsSpecificCultureSupported(string cultureName);
/// <summary>
/// Sets the application's current culture, given an array of culture names.
/// The manager selects the first culture that is supported, or the default culture
/// if none of the specified cultures are supported.
/// </summary>
/// <param name="cultureNames">An array that contains zero or more culture names.</param>
/// <returns>The name of the manager's culture when the operation finishes.</returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="cultureNames"/> is <c>null</c>.
/// </exception>
string SetCulture(params string[] cultureNames);
/// <summary>
/// Sets the application's current culture.
/// If the given culture is not supported, the manager's default culture is selected.
/// <para>
/// If a given specific culture is not supported, its associated neutral culture is selected
/// (if it exists).
/// </para>
/// </summary>
/// <param name="cultureName">
/// The name of the culture, representing a specific or neutral culture.
/// </param>
/// <returns>The name of the manager's culture when the operation finishes.</returns>
/// <exception cref="ArgumentException">
/// <paramref name="cultureName"/> is <c>null</c>, empty, or white space.
/// </exception>
string SetCulture(string cultureName);
/// <summary>
/// Sets the application's current culture to the manager's default culture.
/// </summary>
/// <returns>The name of the manager's culture when the operation finishes.</returns>
string SetDefaultCulture();
/// <summary>
/// Sets the application's current culture to a specific culture.
/// If the given culture is not supported, the manager's default culture is selected.
/// </summary>
/// <param name="cultureName">The name of the culture.</param>
/// <returns>The name of the manager's culture when the operation finishes.</returns>
string SetSpecificCulture(string cultureName);
}
}
18 changes: 0 additions & 18 deletions src/StevenVolckaert.Core/IEnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,6 @@ public static bool IsEmpty<TSource>(this IEnumerable<TSource> source)
return !source.Any();
}

/// <summary>
/// Determines whether a sequence contains no elements.
/// </summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam>
/// <param name="source">The <see cref="IEnumerable{T}"/> instance to check for emptiness. </param>
/// <returns>
/// <c>true</c> if the source sequence contains no elements; otherwise, <c>false</c>.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <c>null</c>.</exception>
[Obsolete("Use of this method is deprecated. Use IEnumerable<T>.IsEmpty<T>() instead.")]
public static bool Empty<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
throw new ArgumentNullException(nameof(source));

return !source.Any();
}

/// <summary>
/// Determines whether none of the elements of a sequence satisfies a condition.
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion src/StevenVolckaert.Core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ developers with writing less code that's easier to read.
The core assembly, named `StevenVolckaert.Core`, contains commonly used functions extending types defined in
the `System` namespace.

`StevenVolckaert.Core` targets the [.NET Standard Library][1] version 1.6.
`StevenVolckaert.Core` targets [.NETStandard 1.5][1] and .NETFramework 4.5.2.

## External links

* [.NET Standard Library][1]

[1]: https://docs.microsoft.com/en-us/dotnet/articles/standard/library
Loading

0 comments on commit 900bb69

Please sign in to comment.