Skip to content

Commit

Permalink
Remove struct constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Friesen committed Jan 28, 2022
1 parent adf6cb7 commit 22b9ac6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/SmartEnum.JsonNet/SmartEnumNameConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Ardalis.SmartEnum.JsonNet

public class SmartEnumNameConverter<TEnum, TValue> : JsonConverter<TEnum>
where TEnum : SmartEnum<TEnum, TValue>
where TValue : struct, IEquatable<TValue>, IComparable<TValue>
where TValue : IEquatable<TValue>, IComparable<TValue>
{
public override bool CanRead => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class TestClass

[JsonConverter(typeof(SmartEnumNameConverter<TestEnumDouble, double>))]
public TestEnumDouble Double { get; set; }

[JsonConverter(typeof(SmartEnumNameConverter<TestEnumString, string>))]
public TestEnumString String { get; set; }
}

static readonly TestClass TestInstance = new TestClass
Expand All @@ -28,14 +31,16 @@ public class TestClass
Int16 = TestEnumInt16.Instance,
Int32 = TestEnumInt32.Instance,
Double = TestEnumDouble.Instance,
String = TestEnumString.Instance,
};

static readonly string JsonString =
@"{
""Bool"": ""Instance"",
""Int16"": ""Instance"",
""Int32"": ""Instance"",
""Double"": ""Instance""
""Double"": ""Instance"",
""String"": ""Instance""
}";

[Fact]
Expand All @@ -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]
Expand All @@ -68,6 +74,7 @@ public void DeserializesNullByDefault()
obj.Int16.Should().BeNull();
obj.Int32.Should().BeNull();
obj.Double.Should().BeNull();
obj.String.Should().BeNull();
}

[Fact]
Expand Down

0 comments on commit 22b9ac6

Please sign in to comment.