From 63ea3eba90f9772201dbb2c0152273e0ba8a4a0d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 22 Nov 2022 20:09:12 +0100 Subject: [PATCH] DataContract usage improvements --- CHANGELOG.md | 2 ++ MLEM.Data/Json/JsonTypeSafeGenericDataHolder.cs | 4 +--- MLEM.Data/Json/JsonTypeSafeWrapper.cs | 5 ++--- MLEM/Misc/GenericDataHolder.cs | 4 ---- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f41d43..9cf4d7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Fixes - Fixed Combination.IsModifierDown querying one of its modifiers instead of all of them Removals +- Removed DataContract attribute from GenericDataHolder - Marked EnumHelper as obsolete due to its reimplementation in [DynamicEnums](https://www.nuget.org/packages/DynamicEnums) ### MLEM.Ui @@ -79,6 +80,7 @@ Improvements - Multi-target net452, making MLEM compatible with MonoGame for consoles - 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 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 7d44685..85e1d94 100644 --- a/MLEM.Data/Json/JsonTypeSafeGenericDataHolder.cs +++ b/MLEM.Data/Json/JsonTypeSafeGenericDataHolder.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Runtime.Serialization; using MLEM.Misc; using Newtonsoft.Json; @@ -8,7 +7,6 @@ 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 . /// - [DataContract] #if NET7_0_OR_GREATER [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for instantiation of JsonTypeSafeWrapper instances might not be available at runtime.")] #endif @@ -16,7 +14,7 @@ namespace MLEM.Data.Json { private static readonly string[] EmptyStrings = new string[0]; - [DataMember(EmitDefaultValue = false)] + [JsonProperty] private Dictionary data; /// diff --git a/MLEM.Data/Json/JsonTypeSafeWrapper.cs b/MLEM.Data/Json/JsonTypeSafeWrapper.cs index 5c46dbd..1bb9ea7 100644 --- a/MLEM.Data/Json/JsonTypeSafeWrapper.cs +++ b/MLEM.Data/Json/JsonTypeSafeWrapper.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Runtime.Serialization; using Newtonsoft.Json; namespace MLEM.Data.Json { @@ -45,12 +44,12 @@ namespace MLEM.Data.Json { } /// - [DataContract] public class JsonTypeSafeWrapper : JsonTypeSafeWrapper { /// public override object Value => this.value; - [DataMember] + + [JsonProperty] private readonly T value; /// diff --git a/MLEM/Misc/GenericDataHolder.cs b/MLEM/Misc/GenericDataHolder.cs index fd5e19e..4014ca9 100644 --- a/MLEM/Misc/GenericDataHolder.cs +++ b/MLEM/Misc/GenericDataHolder.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Runtime.Serialization; namespace MLEM.Misc { /// @@ -7,12 +6,9 @@ namespace MLEM.Misc { /// A lot of MLEM components extend this class to allow for users to add additional data to them easily. /// This implemention uses an underlying that only keeps track of non-default values. /// - [DataContract] public class GenericDataHolder : IGenericDataHolder { private static readonly string[] EmptyStrings = new string[0]; - - [DataMember(EmitDefaultValue = false)] private Dictionary data; ///