diff --git a/src/GameCult.Caching/CultInspectorModel.cs b/src/GameCult.Caching/CultInspectorModel.cs index bb2fbb3f..22a322d3 100644 --- a/src/GameCult.Caching/CultInspectorModel.cs +++ b/src/GameCult.Caching/CultInspectorModel.cs @@ -366,10 +366,14 @@ namespace GameCult.Caching { if (!ElementChoices(elementType).Contains(choice)) throw new ArgumentException($"{choice.Name} is not a choice for {elementType.Name}.", nameof(choice)); - notice = choice == elementType || choice.GetConstructor(Type.EmptyTypes) != null - ? null - : $"{choice.Name} has no parameterless constructor; nothing was created."; - return notice != null ? null : choice == elementType ? CreateDefault(elementType) : Activator.CreateInstance(choice); + var created = choice == elementType ? CreateDefault(choice) + : choice.GetConstructor(Type.EmptyTypes) == null ? null + : Activator.CreateInstance(choice); + // Null is a value only for a Nullable slot; anywhere else it is nothing made. + notice = created == null && !choice.IsValueType + ? $"{choice.Name} is abstract or has no parameterless constructor; nothing was created." + : null; + return created; } // An integer edit as a value of integerType, clamped to that type's range instead of overflowing. diff --git a/tests/GameCult.Caching.Tests/CultInspectorModelTests.cs b/tests/GameCult.Caching.Tests/CultInspectorModelTests.cs index 6f49ae8e..0e5f42bc 100644 --- a/tests/GameCult.Caching.Tests/CultInspectorModelTests.cs +++ b/tests/GameCult.Caching.Tests/CultInspectorModelTests.cs @@ -81,6 +81,10 @@ namespace GameCult.Caching.Tests Assert.That(model.CreateElement(typeof(InspectPicky), typeof(InspectNeedsArgs), out var refused), Is.Null); Assert.That(refused, Does.Contain("parameterless")); + Assert.That(model.CreateElement(typeof(InspectNeedsArgs), typeof(InspectNeedsArgs), out var bare), Is.Null); + Assert.That(bare, Does.Contain("parameterless"), "a plain element type that cannot be made says so; nothing is added"); + Assert.That(model.CreateElement(typeof(int?), typeof(int?), out var nullable), Is.Null); + Assert.That(nullable, Is.Null, "null is a Nullable element, not a failure"); } [Test]