From 89555b813afef9ca10673a62556cf33d86178134 Mon Sep 17 00:00:00 2001 From: Sam Byass Date: Sun, 22 Dec 2024 13:08:16 +0000 Subject: [PATCH] Fix issues from trimming support commit --- Tomlet.Tests/ObjectToStringTests.cs | 4 ++-- Tomlet.Tests/Tomlet.Tests.csproj | 3 ++- Tomlet/TomletMain.cs | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Tomlet.Tests/ObjectToStringTests.cs b/Tomlet.Tests/ObjectToStringTests.cs index a7f4939..bb595fe 100644 --- a/Tomlet.Tests/ObjectToStringTests.cs +++ b/Tomlet.Tests/ObjectToStringTests.cs @@ -106,10 +106,10 @@ public void SerializingAnEmptyObjectGivesAnEmptyString() } [Fact] - public void AttemptingToDirectlySerializeNullThrows() + public void AttemptingToDirectlySerializeNullReturnsNull() { //We need to use a type of T that actually has something to serialize - Assert.Throws(() => TomletMain.DocumentFrom(typeof(SimplePrimitiveTestClass), null!, null)); + Assert.Null(TomletMain.DocumentFrom(typeof(SimplePrimitiveTestClass), null!, null)); } } } \ No newline at end of file diff --git a/Tomlet.Tests/Tomlet.Tests.csproj b/Tomlet.Tests/Tomlet.Tests.csproj index be2aaad..d73dd4c 100644 --- a/Tomlet.Tests/Tomlet.Tests.csproj +++ b/Tomlet.Tests/Tomlet.Tests.csproj @@ -1,9 +1,10 @@ - net7 + net9 false 11 + false diff --git a/Tomlet/TomletMain.cs b/Tomlet/TomletMain.cs index 85b63bb..84381e2 100644 --- a/Tomlet/TomletMain.cs +++ b/Tomlet/TomletMain.cs @@ -69,6 +69,7 @@ public static object To(Type what, TomlValue value, TomlSerializerOptions? optio #if MODERN_DOTNET [return: NotNullIfNotNull("t")] + [UnconditionalSuppressMessage("AOT", "IL2072", Justification = "Any object that is being serialized must have been in the consuming code in order for this call to be occurring, so the dynamic code requirement is already satisfied.")] #if NET7_0_OR_GREATER [RequiresDynamicCode("The native code for underlying implementations of serialize helper methods may not be available for a given type.")] #endif // NET7_0_OR_GREATER @@ -80,7 +81,7 @@ public static object To(Type what, TomlValue value, TomlSerializerOptions? optio if (t == null) return null; - return ValueFrom(typeof(T), t, options); + return ValueFrom(t.GetType(), t, options); } #if MODERN_DOTNET