1+ #nullable enable
2+ #pragma warning disable CS0618 // Type or member is obsolete
3+
4+ namespace tryAGI . OpenAI . JsonConverters
5+ {
6+ /// <inheritdoc />
7+ public class RealtimeAudioFormatsJsonConverter : global ::System . Text . Json . Serialization . JsonConverter < global ::tryAGI . OpenAI . RealtimeAudioFormats >
8+ {
9+ /// <inheritdoc />
10+ public override global ::tryAGI . OpenAI . RealtimeAudioFormats Read (
11+ ref global ::System . Text . Json . Utf8JsonReader reader ,
12+ global ::System . Type typeToConvert ,
13+ global ::System . Text . Json . JsonSerializerOptions options )
14+ {
15+ options = options ?? throw new global ::System . ArgumentNullException ( nameof ( options ) ) ;
16+ var typeInfoResolver = options . TypeInfoResolver ?? throw new global ::System . InvalidOperationException ( "TypeInfoResolver is not set." ) ;
17+
18+ var
19+ readerCopy = reader ;
20+ global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant1 ? value1 = default ;
21+ try
22+ {
23+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant1 ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant1 > ??
24+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant1 ) . Name } ") ;
25+ value1 = global ::System . Text . Json . JsonSerializer . Deserialize ( ref readerCopy , typeInfo ) ;
26+ }
27+ catch ( global ::System . Text . Json . JsonException )
28+ {
29+ }
30+
31+ readerCopy = reader ;
32+ global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant2 ? value2 = default ;
33+ try
34+ {
35+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant2 ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant2 > ??
36+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant2 ) . Name } ") ;
37+ value2 = global ::System . Text . Json . JsonSerializer . Deserialize ( ref readerCopy , typeInfo ) ;
38+ }
39+ catch ( global ::System . Text . Json . JsonException )
40+ {
41+ }
42+
43+ readerCopy = reader ;
44+ global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant3 ? value3 = default ;
45+ try
46+ {
47+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant3 ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant3 > ??
48+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant3 ) . Name } ") ;
49+ value3 = global ::System . Text . Json . JsonSerializer . Deserialize ( ref readerCopy , typeInfo ) ;
50+ }
51+ catch ( global ::System . Text . Json . JsonException )
52+ {
53+ }
54+
55+ var result = new global ::tryAGI . OpenAI . RealtimeAudioFormats (
56+ value1 ,
57+ value2 ,
58+ value3
59+ ) ;
60+
61+ if ( value1 != null )
62+ {
63+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant1 ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant1 > ??
64+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant1 ) . Name } ") ;
65+ _ = global ::System . Text . Json . JsonSerializer . Deserialize ( ref reader , typeInfo ) ;
66+ }
67+ else if ( value2 != null )
68+ {
69+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant2 ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant2 > ??
70+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant2 ) . Name } ") ;
71+ _ = global ::System . Text . Json . JsonSerializer . Deserialize ( ref reader , typeInfo ) ;
72+ }
73+ else if ( value3 != null )
74+ {
75+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant3 ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant3 > ??
76+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant3 ) . Name } ") ;
77+ _ = global ::System . Text . Json . JsonSerializer . Deserialize ( ref reader , typeInfo ) ;
78+ }
79+
80+ return result ;
81+ }
82+
83+ /// <inheritdoc />
84+ public override void Write (
85+ global ::System . Text . Json . Utf8JsonWriter writer ,
86+ global ::tryAGI . OpenAI . RealtimeAudioFormats value ,
87+ global ::System . Text . Json . JsonSerializerOptions options )
88+ {
89+ options = options ?? throw new global ::System . ArgumentNullException ( nameof ( options ) ) ;
90+ var typeInfoResolver = options . TypeInfoResolver ?? throw new global ::System . InvalidOperationException ( "TypeInfoResolver is not set." ) ;
91+
92+ if ( value . IsValue1 )
93+ {
94+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant1 ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant1 ? > ??
95+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant1 ) . Name } ") ;
96+ global ::System . Text . Json . JsonSerializer . Serialize ( writer , value . Value1 , typeInfo ) ;
97+ }
98+ else if ( value . IsValue2 )
99+ {
100+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant2 ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant2 ? > ??
101+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant2 ) . Name } ") ;
102+ global ::System . Text . Json . JsonSerializer . Serialize ( writer , value . Value2 , typeInfo ) ;
103+ }
104+ else if ( value . IsValue3 )
105+ {
106+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant3 ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant3 ? > ??
107+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . RealtimeAudioFormatsVariant3 ) . Name } ") ;
108+ global ::System . Text . Json . JsonSerializer . Serialize ( writer , value . Value3 , typeInfo ) ;
109+ }
110+ }
111+ }
112+ }
0 commit comments