-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBitArrayConverter.cs
41 lines (33 loc) · 1.19 KB
/
BitArrayConverter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using FreeAllegiance.IGCCore.Modules;
using FreeAllegiance.IGCCore.Util;
using System.Collections;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
namespace CoreExporter
{
internal class BitArrayConverter<T> : JsonConverter<System.Collections.BitArray> where T : System.Enum
{
public override BitArray? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
public override void Write(Utf8JsonWriter writer, BitArray value, JsonSerializerOptions options)
{
//writer.WriteStartObject();
//writer.WriteString("_type", value.GetType().AssemblyQualifiedName);
JsonArray array = new JsonArray();
for (int i = 0; i < value.Count; i++)
{
if (value[i] == true)
{
array.Add(Enum.GetName(typeof(T), i));
}
}
//writer.WritePropertyName("PartType");
array.WriteTo(writer);
//writer.WriteEndObject();
}
}
}