From 92353e40e62c92280934bd37ac2b6299813aaef8 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 22 Nov 2022 21:51:42 +0100 Subject: [PATCH] Allow adding JsonTypeSafeWrapper instances to JsonTypeSafeGenericDataHolder directly --- CHANGELOG.md | 1 + MLEM.Data/Json/JsonTypeSafeGenericDataHolder.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cf4d7e..aea3067 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ Improvements - Added trimming and AOT annotations and made MLEM.Data trimmable - Store a RuntimeTexturePacker packed texture region's source region - Use JSON.NET attributes in favor of DataContract and DataMember +- Allow adding JsonTypeSafeWrapper instances to JsonTypeSafeGenericDataHolder directly Fixes - Fixed data texture atlases not allowing most characters in their region names diff --git a/MLEM.Data/Json/JsonTypeSafeGenericDataHolder.cs b/MLEM.Data/Json/JsonTypeSafeGenericDataHolder.cs index 85e1d94..2146ced 100644 --- a/MLEM.Data/Json/JsonTypeSafeGenericDataHolder.cs +++ b/MLEM.Data/Json/JsonTypeSafeGenericDataHolder.cs @@ -6,6 +6,7 @@ namespace MLEM.Data.Json { /// /// An represents an object that can hold generic key-value based data. /// This class uses for each object stored to ensure that objects with a custom get deserialized as an instance of their original type if is not set to . + /// Note that, using , adding instances directly is also possible. /// #if NET7_0_OR_GREATER [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for instantiation of JsonTypeSafeWrapper instances might not be available at runtime.")] @@ -25,7 +26,7 @@ namespace MLEM.Data.Json { } else { if (this.data == null) this.data = new Dictionary(); - this.data[key] = JsonTypeSafeWrapper.Of(data); + this.data[key] = data as JsonTypeSafeWrapper ?? JsonTypeSafeWrapper.Of(data); } }