openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
achandmsft-patch-1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Generated/Internal/ChangeTrackingList.cs

150lines · modecode

1// <auto-generated/>
2
3#nullable disable
4
5using System;
6using System.Collections;
7using System.Collections.Generic;
8using System.Linq;
9
10namespace OpenAI
11{
12 internal partial class ChangeTrackingList<T> : IList<T>, IReadOnlyList<T>
13 {
14 private IList<T> _innerList;
15
16 public ChangeTrackingList()
17 {
18 }
19
20 public ChangeTrackingList(IList<T> innerList)
21 {
22 if (innerList != null)
23 {
24 _innerList = innerList;
25 }
26 }
27
28 public ChangeTrackingList(IReadOnlyList<T> innerList)
29 {
30 if (innerList != null)
31 {
32 _innerList = innerList.ToList();
33 }
34 }
35
36 public bool IsUndefined => _innerList == null;
37
38 public int Count => IsUndefined ? 0 : EnsureList().Count;
39
40 public bool IsReadOnly => IsUndefined ? false : EnsureList().IsReadOnly;
41
42 public T this[int index]
43 {
44 get
45 {
46 if (IsUndefined)
47 {
48 throw new ArgumentOutOfRangeException(nameof(index));
49 }
50 return EnsureList()[index];
51 }
52 set
53 {
54 if (IsUndefined)
55 {
56 throw new ArgumentOutOfRangeException(nameof(index));
57 }
58 EnsureList()[index] = value;
59 }
60 }
61
62 public void Reset()
63 {
64 _innerList = null;
65 }
66
67 public IEnumerator<T> GetEnumerator()
68 {
69 if (IsUndefined)
70 {
71 IEnumerator<T> enumerateEmpty()
72 {
73 yield break;
74 }
75 return enumerateEmpty();
76 }
77 return EnsureList().GetEnumerator();
78 }
79
80 IEnumerator IEnumerable.GetEnumerator()
81 {
82 return GetEnumerator();
83 }
84
85 public void Add(T item)
86 {
87 EnsureList().Add(item);
88 }
89
90 public void Clear()
91 {
92 EnsureList().Clear();
93 }
94
95 public bool Contains(T item)
96 {
97 if (IsUndefined)
98 {
99 return false;
100 }
101 return EnsureList().Contains(item);
102 }
103
104 public void CopyTo(T[] array, int arrayIndex)
105 {
106 if (IsUndefined)
107 {
108 return;
109 }
110 EnsureList().CopyTo(array, arrayIndex);
111 }
112
113 public bool Remove(T item)
114 {
115 if (IsUndefined)
116 {
117 return false;
118 }
119 return EnsureList().Remove(item);
120 }
121
122 public int IndexOf(T item)
123 {
124 if (IsUndefined)
125 {
126 return -1;
127 }
128 return EnsureList().IndexOf(item);
129 }
130
131 public void Insert(int index, T item)
132 {
133 EnsureList().Insert(index, item);
134 }
135
136 public void RemoveAt(int index)
137 {
138 if (IsUndefined)
139 {
140 throw new ArgumentOutOfRangeException(nameof(index));
141 }
142 EnsureList().RemoveAt(index);
143 }
144
145 public IList<T> EnsureList()
146 {
147 return _innerList ??= new List<T>();
148 }
149 }
150}
151