-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathCustomCallingContextInternal.Serialization.cs
More file actions
102 lines (95 loc) · 3.89 KB
/
CustomCallingContextInternal.Serialization.cs
File metadata and controls
102 lines (95 loc) · 3.89 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// <auto-generated/>
#nullable disable
using System.Collections.Generic;
using System.Text.Json;
using Azure.Core;
namespace Azure.Communication.CallAutomation
{
internal partial class CustomCallingContextInternal : IUtf8JsonSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (Optional.IsCollectionDefined(VoipHeaders))
{
writer.WritePropertyName("voipHeaders"u8);
writer.WriteStartObject();
foreach (var item in VoipHeaders)
{
writer.WritePropertyName(item.Key);
writer.WriteStringValue(item.Value);
}
writer.WriteEndObject();
}
if (Optional.IsCollectionDefined(SipHeaders))
{
writer.WritePropertyName("sipHeaders"u8);
writer.WriteStartObject();
foreach (var item in SipHeaders)
{
writer.WritePropertyName(item.Key);
writer.WriteStringValue(item.Value);
}
writer.WriteEndObject();
}
writer.WriteEndObject();
}
internal static CustomCallingContextInternal DeserializeCustomCallingContextInternal(JsonElement element)
{
if (element.ValueKind == JsonValueKind.Null)
{
return null;
}
IDictionary<string, string> voipHeaders = default;
IDictionary<string, string> sipHeaders = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("voipHeaders"u8))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
Dictionary<string, string> dictionary = new Dictionary<string, string>();
foreach (var property0 in property.Value.EnumerateObject())
{
dictionary.Add(property0.Name, property0.Value.GetString());
}
voipHeaders = dictionary;
continue;
}
if (property.NameEquals("sipHeaders"u8))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
Dictionary<string, string> dictionary = new Dictionary<string, string>();
foreach (var property0 in property.Value.EnumerateObject())
{
dictionary.Add(property0.Name, property0.Value.GetString());
}
sipHeaders = dictionary;
continue;
}
}
return new CustomCallingContextInternal(voipHeaders ?? new ChangeTrackingDictionary<string, string>(), sipHeaders ?? new ChangeTrackingDictionary<string, string>());
}
/// <summary> Deserializes the model from a raw response. </summary>
/// <param name="response"> The response to deserialize the model from. </param>
internal static CustomCallingContextInternal FromResponse(Response response)
{
using var document = JsonDocument.Parse(response.Content);
return DeserializeCustomCallingContextInternal(document.RootElement);
}
/// <summary> Convert into a <see cref="RequestContent"/>. </summary>
internal virtual RequestContent ToRequestContent()
{
var content = new Utf8JsonRequestContent();
content.JsonWriter.WriteObjectValue(this);
return content;
}
}
}