Skip to content

Commit

Permalink
Close #46
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-j-engdahl committed Aug 16, 2019
1 parent 4b4a52e commit f4c872c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- XGettext-Xaml annotated locations match the given parameter instead of just the filename. This is useful when making PoEdit friendly .po files where the locations must be relative. Thanks to @PGPoulsen for the PR.

### Fixed
- [46](https://github.com/robert-j-engdahl/ngettext-wpf/issues/46) Crash when localizing invalid enum value

## [1.2.5-alpha] - 2019-06-13
### Added
- Experimental TranslationSerializer for making localized json objects that can be used from TSQL like so
Expand Down
12 changes: 12 additions & 0 deletions NGettext.Wpf.Tests/EnumTranslation/EnumLocalizerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ public enum TestEnum
EnumValueWithoutMsgId,
}

public enum EmptyEnum
{
}

[Fact]
public void Handles_Invalid_Enum_Member()
{
var e = Record.Exception(() => _target.LocalizeEnum(default(EmptyEnum)));

Assert.Null(e);
}

[Theory]
[InlineData(TestEnum.EnumValue, "enum value")]
[InlineData(TestEnum.AnotherEnumValue, "another enum value")]
Expand Down
2 changes: 1 addition & 1 deletion NGettext.Wpf/EnumTranslation/EnumLocalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public string LocalizeEnum(Enum value)
{
var type = value.GetType();
var enumMemberName = value.ToString();
var msgIdAttribute = (EnumMsgIdAttribute)type.GetMember(enumMemberName).Single().GetCustomAttribute(typeof(EnumMsgIdAttribute), true);
var msgIdAttribute = (EnumMsgIdAttribute)type.GetMember(enumMemberName).SingleOrDefault()?.GetCustomAttribute(typeof(EnumMsgIdAttribute), true);

if (msgIdAttribute is null)
{
Expand Down

0 comments on commit f4c872c

Please sign in to comment.