openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Generated/Internal/ChangeTrackingDictionary.cs

164lines · modeblame

9f9f2936Jose Arriaga Maldonado2 years ago1// <auto-generated/>
2
3#nullable disable
4
5using System;
6using System.Collections;
7using System.Collections.Generic;
8
9namespace OpenAI
10{
11internal class ChangeTrackingDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IReadOnlyDictionary<TKey, TValue> where TKey : notnull
12{
13private IDictionary<TKey, TValue> _innerDictionary;
14
15public ChangeTrackingDictionary()
16{
17}
18
19public ChangeTrackingDictionary(IDictionary<TKey, TValue> dictionary)
20{
21if (dictionary == null)
22{
23return;
24}
25_innerDictionary = new Dictionary<TKey, TValue>(dictionary);
26}
27
28public ChangeTrackingDictionary(IReadOnlyDictionary<TKey, TValue> dictionary)
29{
30if (dictionary == null)
31{
32return;
33}
34_innerDictionary = new Dictionary<TKey, TValue>();
35foreach (var pair in dictionary)
36{
37_innerDictionary.Add(pair);
38}
39}
40
41public bool IsUndefined => _innerDictionary == null;
42
43public int Count => IsUndefined ? 0 : EnsureDictionary().Count;
44
45public bool IsReadOnly => IsUndefined ? false : EnsureDictionary().IsReadOnly;
46
47public ICollection<TKey> Keys => IsUndefined ? Array.Empty<TKey>() : EnsureDictionary().Keys;
48
49public ICollection<TValue> Values => IsUndefined ? Array.Empty<TValue>() : EnsureDictionary().Values;
50
51public TValue this[TKey key]
52{
53get
54{
55if (IsUndefined)
56{
57throw new KeyNotFoundException(nameof(key));
58}
59return EnsureDictionary()[key];
60}
61set
62{
63EnsureDictionary()[key] = value;
64}
65}
66
67IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys => Keys;
68
69IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values => Values;
70
71public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
72{
73if (IsUndefined)
74{
75IEnumerator<KeyValuePair<TKey, TValue>> enumerateEmpty()
76{
77yield break;
78}
79return enumerateEmpty();
80}
81return EnsureDictionary().GetEnumerator();
82}
83
84IEnumerator IEnumerable.GetEnumerator()
85{
86return GetEnumerator();
87}
88
89public void Add(KeyValuePair<TKey, TValue> item)
90{
91EnsureDictionary().Add(item);
92}
93
94public void Clear()
95{
96EnsureDictionary().Clear();
97}
98
99public bool Contains(KeyValuePair<TKey, TValue> item)
100{
101if (IsUndefined)
102{
103return false;
104}
105return EnsureDictionary().Contains(item);
106}
107
108public void CopyTo(KeyValuePair<TKey, TValue>[] array, int index)
109{
110if (IsUndefined)
111{
112return;
113}
114EnsureDictionary().CopyTo(array, index);
115}
116
117public bool Remove(KeyValuePair<TKey, TValue> item)
118{
119if (IsUndefined)
120{
121return false;
122}
123return EnsureDictionary().Remove(item);
124}
125
126public void Add(TKey key, TValue value)
127{
128EnsureDictionary().Add(key, value);
129}
130
131public bool ContainsKey(TKey key)
132{
133if (IsUndefined)
134{
135return false;
136}
137return EnsureDictionary().ContainsKey(key);
138}
139
140public bool Remove(TKey key)
141{
142if (IsUndefined)
143{
144return false;
145}
146return EnsureDictionary().Remove(key);
147}
148
149public bool TryGetValue(TKey key, out TValue value)
150{
151if (IsUndefined)
152{
153value = default;
154return false;
155}
156return EnsureDictionary().TryGetValue(key, out value);
157}
158
159public IDictionary<TKey, TValue> EnsureDictionary()
160{
161return _innerDictionary ??= new Dictionary<TKey, TValue>();
162}
163}
164}