From 22b9ac670549e778093b4a5ccf3adf2dc76e97f0 Mon Sep 17 00:00:00 2001 From: Brian Friesen Date: Fri, 28 Jan 2022 10:41:24 -0500 Subject: [PATCH] Remove struct constraint --- src/SmartEnum.JsonNet/SmartEnumNameConverter.cs | 2 +- .../SmartEnumNameConverterTests.cs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/SmartEnum.JsonNet/SmartEnumNameConverter.cs b/src/SmartEnum.JsonNet/SmartEnumNameConverter.cs index 296103f0..96b3bfbe 100644 --- a/src/SmartEnum.JsonNet/SmartEnumNameConverter.cs +++ b/src/SmartEnum.JsonNet/SmartEnumNameConverter.cs @@ -5,7 +5,7 @@ namespace Ardalis.SmartEnum.JsonNet public class SmartEnumNameConverter : JsonConverter where TEnum : SmartEnum - where TValue : struct, IEquatable, IComparable + where TValue : IEquatable, IComparable { public override bool CanRead => true; diff --git a/test/SmartEnum.JsonNet.UnitTests/SmartEnumNameConverterTests.cs b/test/SmartEnum.JsonNet.UnitTests/SmartEnumNameConverterTests.cs index a54292a1..a24b25bc 100644 --- a/test/SmartEnum.JsonNet.UnitTests/SmartEnumNameConverterTests.cs +++ b/test/SmartEnum.JsonNet.UnitTests/SmartEnumNameConverterTests.cs @@ -20,6 +20,9 @@ public class TestClass [JsonConverter(typeof(SmartEnumNameConverter))] public TestEnumDouble Double { get; set; } + + [JsonConverter(typeof(SmartEnumNameConverter))] + public TestEnumString String { get; set; } } static readonly TestClass TestInstance = new TestClass @@ -28,6 +31,7 @@ public class TestClass Int16 = TestEnumInt16.Instance, Int32 = TestEnumInt32.Instance, Double = TestEnumDouble.Instance, + String = TestEnumString.Instance, }; static readonly string JsonString = @@ -35,7 +39,8 @@ public class TestClass ""Bool"": ""Instance"", ""Int16"": ""Instance"", ""Int32"": ""Instance"", - ""Double"": ""Instance"" + ""Double"": ""Instance"", + ""String"": ""Instance"" }"; [Fact] @@ -55,6 +60,7 @@ public void DeserializesNames() obj.Int16.Should().BeSameAs(TestEnumInt16.Instance); obj.Int32.Should().BeSameAs(TestEnumInt32.Instance); obj.Double.Should().BeSameAs(TestEnumDouble.Instance); + obj.String.Should().BeSameAs(TestEnumString.Instance); } [Fact] @@ -68,6 +74,7 @@ public void DeserializesNullByDefault() obj.Int16.Should().BeNull(); obj.Int32.Should().BeNull(); obj.Double.Should().BeNull(); + obj.String.Should().BeNull(); } [Fact]