diff --git a/src/Serializers/SerializerResolver.cs b/src/Serializers/SerializerResolver.cs index 1ee45d9..a4dfa8f 100644 --- a/src/Serializers/SerializerResolver.cs +++ b/src/Serializers/SerializerResolver.cs @@ -51,6 +51,11 @@ public static void Register(DataDirection direction = DataDirect /// The serializer to apply public static void Register(Type targetType, DataDirection direction = DataDirection.All) where TSerializer : ApiSerializer, new() { + if (!targetType.IsClass) + { + throw new ArgumentException($"{targetType.Name} is not a class", nameof(targetType)); + } + if (direction.HasFlag(DataDirection.In)) { DeserializerMap[targetType] = typeof(TSerializer); @@ -79,7 +84,7 @@ public static void Unregister(DataDirection direction = DataDirection.All) wh /// Whether this serializer should be removed from incoming/outgoing data public static void Unregister(Type targetType, DataDirection direction = DataDirection.All) { - if (targetType.IsClass) + if (!targetType.IsClass) { throw new ArgumentException($"{targetType.Name} is not a class", nameof(targetType)); } diff --git a/tests/Serializers/SerializerResolverTests.cs b/tests/Serializers/SerializerResolverTests.cs index 41bf02c..0323af8 100644 --- a/tests/Serializers/SerializerResolverTests.cs +++ b/tests/Serializers/SerializerResolverTests.cs @@ -20,6 +20,8 @@ public void Setup() // anothertestobject will use the dummyserializer SerializerResolver.Register(); + + SerializerResolver.Register(typeof(TestContainer<>)); } [Test] @@ -27,6 +29,8 @@ public void TestResolution() { Assert.AreEqual(typeof(ApiXmlSerializer), Client.Serializer.Resolve(DataDirection.In).GetType()); Assert.AreEqual(typeof(ApiJsonSerializer), Client.Serializer.Resolve(DataDirection.Out).GetType()); + + Assert.AreEqual(typeof(DummySerializer), Client.Serializer.Resolve>(DataDirection.In).GetType()); } [Test] @@ -66,6 +70,11 @@ public class YetAnotherTestObject { } + public class TestContainer + { + public T Item { get; set; } + } + public class DummySerializer : ApiSerializer { public override string ContentType => "nothing";