Преглед на файлове

Fixed Editor on DynamicGridColumn being serialised

Kenric Nugteren преди 1 седмица
родител
ревизия
cf0f575b4c

+ 22 - 0
InABox.Core/Serialization.cs

@@ -47,6 +47,22 @@ namespace InABox.Core
             }
         }
 
+        /// <summary>
+        /// Remove properties marked as <see cref="DoNotSerialize"/>
+        /// </summary>
+        /// <param name="typeInfo"></param>
+        private static void DoNotSerializeModifier(JsonTypeInfo typeInfo)
+        {
+            if (typeInfo.Kind == JsonTypeInfoKind.Object)
+            {
+                var toRemove = typeInfo.Properties.Where(x => x.AttributeProvider?.IsDefined(typeof(DoNotSerialize), false) == true).ToList();
+                foreach (var prop in toRemove)
+                {
+                    typeInfo.Properties.Remove(prop);
+                }
+            }
+        }
+
         public static List<JsonConverter> DefaultConverters { get; } = new List<JsonConverter>()
         {
             new CoreTableJsonConverter(),
@@ -78,6 +94,12 @@ namespace InABox.Core
             {
                 settings.TypeInfoResolver = new PopulateTypeInfoResolver(new DefaultJsonTypeInfoResolver());
             }
+            else
+            {
+                settings.TypeInfoResolver = new DefaultJsonTypeInfoResolver();
+            }
+            settings.TypeInfoResolver = settings.TypeInfoResolver
+                .WithAddedModifier(DoNotSerializeModifier);
 
             settings.WriteIndented = indented;
             return settings;

+ 5 - 0
InABox.RPC.Shared/RPCMessage.cs

@@ -4,6 +4,11 @@ using InABox.Core;
 
 namespace InABox.Rpc
 {
+    // Note that this implements both ISerializeBinary and ICoreFormattable, which is annoying duplicate code. The reason that these can't be combined
+    // is that ICoreFormattable *must* be able to be used by netstandard2.0 for Logikal, and therefore must live outside of InABox.Core. Hence, we need
+    // two interfaces. If we wanted to combine them, the interface for the ISerializeBinary would need to be changed to be able to just use a
+    // CoreBinaryWriter/Reader, and this would introduce version inconsistency for communications. Hence, this would only be able to be done once we
+    // switch from old mobile app and therefore can introduce a breaking change for a version (e.g., version 9).
     [Serializable]
     public partial class RpcMessage : ISerializeBinary, ICoreFormattable
     {

+ 2 - 7
inabox.wpf/Dashboard/DynamicDashboard.cs

@@ -92,13 +92,8 @@ public static class DynamicDashboardUtils
     private static JsonSerializerOptions SerializationSettings()
     {
         var settings = Serialization.CreateSerializerSettings();
-        settings.TypeInfoResolver = new DefaultJsonTypeInfoResolver
-        {
-            Modifiers =
-            {
-                Serialization.WritablePropertiesOnly
-            }
-        };
+        settings.TypeInfoResolver = (settings.TypeInfoResolver ?? new DefaultJsonTypeInfoResolver())
+            .WithAddedModifier(Serialization.WritablePropertiesOnly);
         return settings;
     }
 

+ 2 - 0
inabox.wpf/DynamicGrid/DynamicGridColumn/DynamicGridColumn.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Text.Json.Serialization;
 using System.Windows;
 using InABox.Core;
 
@@ -96,6 +97,7 @@ public class DynamicGridColumn : DynamicColumnBase
     [EditorSequence(5)]
     public Alignment Alignment { get; set; }
 
+    [DoNotSerialize]
     public BaseEditor Editor { get; set; }
 
     public VerticalAlignment VerticalAlignment() => Alignment.VerticalAlignment();

+ 2 - 1
inabox.wpf/DynamicGrid/DynamicGridCommon.cs

@@ -17,7 +17,8 @@ public abstract class DynamicColumnBase : BaseObject, IDynamicColumnBase
     }
 
     public event DynamicColumnEntityChangedEvent? EntityChanged;
-    
+
+	[DoNotSerialize]
     public object? Tag { get; set; }
     
 }