Beispiel #1
0
        public override DicomDataset[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            var datasetList = new List <DicomDataset>();

            if (reader.TokenType != JsonTokenType.StartArray)
            {
                return(datasetList.ToArray());
            }
            reader.Read();
            var conv = new DicomJsonConverter(writeTagsAsKeywords: _writeTagsAsKeywords);

            while (reader.TokenType != JsonTokenType.EndArray)
            {
                DicomDataset ds;
                switch (reader.TokenType)
                {
                case JsonTokenType.StartObject:
                    ds = conv.Read(ref reader, typeToConvert, options);
                    reader.AssumeAndSkip(JsonTokenType.EndObject);
                    break;

                case JsonTokenType.Null:
                    ds = null;
                    reader.Read();
                    break;

                default:
                    throw new JsonException($"Expected either the start of an object or null but found '{reader.TokenType}'.");
                }

                datasetList.Add(ds);
            }
            reader.Read();
            return(datasetList.ToArray());
        }
Beispiel #2
0
        public override void Write(Utf8JsonWriter writer, DicomDataset[] value, JsonSerializerOptions options)
        {
            var conv = new DicomJsonConverter(writeTagsAsKeywords: _writeTagsAsKeywords);

            writer.WriteStartArray();
            foreach (var ds in value)
            {
                conv.Write(writer, ds, options);
            }
            writer.WriteEndArray();
        }