diff --git a/Gu.Xml.Tests/XmlTests.SerializeWithDataContractAttributes.cs b/Gu.Xml.Tests/XmlTests.SerializeWithDataContractAttributes.cs index 3f3da90..c01a75e 100644 --- a/Gu.Xml.Tests/XmlTests.SerializeWithDataContractAttributes.cs +++ b/Gu.Xml.Tests/XmlTests.SerializeWithDataContractAttributes.cs @@ -23,6 +23,8 @@ public class SerializeWithDataContractAttributes new TestCaseData(new FieldWithIgnoreDataMemberAttribute { Value = 1 }), new TestCaseData(new FieldWithDataMemberAttribute { Value = 1 }), new TestCaseData(new FieldWithDataMemberAttributeExplicitName { Value = 1 }), + new TestCaseData(new WithWithEnumMemberAttribute { Value = WithEnumMemberAttribute.One }), + new TestCaseData(new WithWithEnumMemberAttribute { Value = WithEnumMemberAttribute.Two }), }; [TestCaseSource(nameof(Values))] @@ -117,6 +119,20 @@ public class FieldWithIgnoreDataMemberAttribute [IgnoreDataMember] public int Value { get; set; } } + + public class WithWithEnumMemberAttribute + { + public WithEnumMemberAttribute Value { get; set; } + } + + [DataContract] + public enum WithEnumMemberAttribute + { + [EnumMember(Value = "Single")] + One, + [EnumMember(Value = "Double")] + Two, + } } } } \ No newline at end of file diff --git a/Gu.Xml/Writers/EnumWriter{T}.cs b/Gu.Xml/Writers/EnumWriter{T}.cs index ab6fc1b..2f69d4d 100644 --- a/Gu.Xml/Writers/EnumWriter{T}.cs +++ b/Gu.Xml/Writers/EnumWriter{T}.cs @@ -48,7 +48,8 @@ private string ToString(T value) if (typeof(T).GetMember(value.ToString()).TryFirst(out var member)) { if (TryGetNameFromAttribute(member, x => x.Name, out var name) || - TryGetNameFromAttribute(member, x => x.Name, out name)) + TryGetNameFromAttribute(member, x => x.Name, out name) || + TryGetNameFromAttribute(member, x => x.Value, out name)) { return name; }