-
Notifications
You must be signed in to change notification settings - Fork 14
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
Testable initialization of Gu.Localizalization.Culture #85
Conversation
Added test for getting invalid culture.
{ | ||
get | ||
{ | ||
return AllCultures.Select(x => TryGetRegion(x, out var region) ? region : null).Where(x => x != null).ToList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LINQ in the getter is potentially expensive here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be the first time at least. The RegionInfo is cached by Microsoft, so it might not be that bad. Are you up for profiling this?
@@ -8,52 +8,18 @@ namespace Gu.Localization | |||
/// <summary> Utility class for <see cref="CultureInfo"/> </summary> | |||
internal static class Culture | |||
{ | |||
internal static readonly IReadOnlyList<CultureInfo> AllCultures = | |||
internal static IReadOnlyList<CultureInfo> AllCultures = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't be readonly
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary for functionality to be settable. But it makes testing TryGet possible.
This simplifies the initialization of the internal class Gu.Localization.Culture. And by virtue of making AllCultures settable, the class is a little easier to test. It is also another solution to issue #82 .