Update README.md

Alphons van der Heijden <alphons@heijden.com> 15 Dec 2023, 16:39
9dd62593f887214ba1486770ac1c4049348a163e
1 files changed
  • README.md
diff --git a/README.md b/README.md
index c5150f2..5319a51 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,6 @@ Emulates jsonIgnore, can be anonymous objects (sort of), aslo filters empty obje
## class JsonSerializerIgn
```c#
-
using System.Collections;
using System.Text.Json.Serialization.Metadata;
@@ -24,6 +23,15 @@ public static class JsonSerializerIgn
if (value is IList list)
return list.Count > 0;
+ if (value is bool b)
+ return b;
+
+ if (value is int i)
+ return i != 0;
+
+ if (value is ValueType)
+ return true;
+
foreach (var property in value.GetType().GetProperties())
{
if (Array.IndexOf(Ignoring, property.Name) >= 0)
@@ -57,6 +65,32 @@ public static class JsonSerializerIgn
return JsonSerializer.Serialize(obj, options);
}
}
+```
+
+## Test program
+
+```c#
+using System.Text.Json;
+using VMTux.VMTuxEmulator.DataModel.Form;
+
+namespace ConsoleApp1;
+
+internal class Program
+{
+ async static Task Main(string[] args)
+ {
+ var vm = DataEngine.GetVm();
+
+ var options = new JsonSerializerOptions() { WriteIndented = true };
+
+ var json0 = JsonSerializer.Serialize(vm, options);
+ var json1 = JsonSerializerIgn.Serialize(vm, options, ["Name1", "Name2", "Name3"]);
+
+ await File.WriteAllTextAsync("json0.json", json0);
+ await File.WriteAllTextAsync("json1.json", json1);
+ }
+}
+```
```