-
Notifications
You must be signed in to change notification settings - Fork 748
Expand file tree
/
Copy pathFingerprintsStjConverter.cs
More file actions
42 lines (37 loc) · 1.39 KB
/
FingerprintsStjConverter.cs
File metadata and controls
42 lines (37 loc) · 1.39 KB
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
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using NuGet.Packaging.Core;
namespace NuGet.Protocol.Converters
{
internal sealed class FingerprintsStjConverter : JsonConverter<Fingerprints>
{
public override Fingerprints Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartObject)
{
throw new JsonException();
}
var dict = new Dictionary<string, string>();
while (reader.Read() && reader.TokenType == JsonTokenType.PropertyName)
{
string key = reader.GetString()!;
reader.Read();
dict[key] = reader.GetString() ?? string.Empty;
}
return new Fingerprints(dict);
}
public override void Write(Utf8JsonWriter writer, Fingerprints value, JsonSerializerOptions options)
{
writer.WriteStartObject();
foreach (KeyValuePair<string, string> kvp in value)
{
writer.WriteString(kvp.Key, kvp.Value);
}
writer.WriteEndObject();
}
}
}