From 8e06e54325bec73121f5d786aea3b4d3466520ce Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 13 Feb 2021 17:25:46 +0100 Subject: [PATCH] Removed JsonExtensions --- MLEM.Data/Json/JsonExtensions.cs | 40 -------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 MLEM.Data/Json/JsonExtensions.cs diff --git a/MLEM.Data/Json/JsonExtensions.cs b/MLEM.Data/Json/JsonExtensions.cs deleted file mode 100644 index c02f975..0000000 --- a/MLEM.Data/Json/JsonExtensions.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Reflection; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; - -namespace MLEM.Data.Json { - /// - /// A set of extensions for dealing with the Newtonsoft.JSON . - /// - public static class JsonExtensions { - - /// - /// Changes the to a contract resolver that queries each newly created and allows modifying it easily. - /// This removes the need to create a new contract resolver class for modifying created json properties. - /// - /// The serializer to which to add the property modifier - /// A function that takes in the json property and allows returning a modified property (or the same one) - /// - public static JsonSerializer SetPropertyModifier(this JsonSerializer serializer, Func propertyModifier) { - serializer.ContractResolver = new PropertyModifierResolver(propertyModifier); - return serializer; - } - - private class PropertyModifierResolver : DefaultContractResolver { - - private readonly Func propertyModifier; - - public PropertyModifierResolver(Func propertyModifier) { - this.propertyModifier = propertyModifier; - } - - protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { - var property = base.CreateProperty(member, memberSerialization); - return this.propertyModifier(property); - } - - } - - } -} \ No newline at end of file