-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBitArrayToIntConverter.cs
47 lines (37 loc) · 1.35 KB
/
BitArrayToIntConverter.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
42
43
44
45
46
47
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 BitArrayToIntConverter : JsonConverter<System.Collections.BitArray>
{
private int _additionalIncrement = 0;
public BitArrayToIntConverter(int additionalIncrement) {
_additionalIncrement = additionalIncrement;
}
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(i + _additionalIncrement);
}
}
//writer.WritePropertyName("PartType");
array.WriteTo(writer);
//writer.WriteEndObject();
}
}
}