Browse Source

Added "WritablePropertiesOnly" Modifier

Kenric Nugteren 1 week ago
parent
commit
23ee30460d
1 changed files with 15 additions and 1 deletions
  1. 15 1
      InABox.Core/Serialization.cs

+ 15 - 1
InABox.Core/Serialization.cs

@@ -31,7 +31,21 @@ namespace InABox.Core
 
     public static class Serialization
     {
-        //private static JsonSerializerOptions? _serializerSettings;
+        /// <summary>
+        /// TypeInfoResolver modifier that removes properties that don't have setters.
+        /// </summary>
+        /// <param name="typeInfo"></param>
+        public static void WritablePropertiesOnly(JsonTypeInfo typeInfo)
+        {
+            if(typeInfo.Kind == JsonTypeInfoKind.Object)
+            {
+                var toRemove = typeInfo.Properties.Where(x => x.Set is null).ToList();
+                foreach(var prop in toRemove)
+                {
+                    typeInfo.Properties.Remove(prop);
+                }
+            }
+        }
 
         private static JsonConverter[]? _converters;