@@ -39,7 +39,11 @@ public static ReadResult Load(MemoryStream stream,
39
39
string format = null ,
40
40
OpenApiReaderSettings settings = null )
41
41
{
42
+ #if NET6_0_OR_GREATER
43
+ ArgumentNullException . ThrowIfNull ( stream ) ;
44
+ #else
42
45
if ( stream is null ) throw new ArgumentNullException ( nameof ( stream ) ) ;
46
+ #endif
43
47
settings ??= new OpenApiReaderSettings ( ) ;
44
48
45
49
// Get the format of the stream if not provided
@@ -112,7 +116,11 @@ public static async Task<T> LoadAsync<T>(string url, OpenApiSpecVersion version,
112
116
/// <returns></returns>
113
117
public static async Task < ReadResult > LoadAsync ( Stream input , string format = null , OpenApiReaderSettings settings = null , CancellationToken cancellationToken = default )
114
118
{
119
+ #if NET6_0_OR_GREATER
120
+ ArgumentNullException . ThrowIfNull ( input ) ;
121
+ #else
115
122
if ( input is null ) throw new ArgumentNullException ( nameof ( input ) ) ;
123
+ #endif
116
124
settings ??= new OpenApiReaderSettings ( ) ;
117
125
118
126
Stream preparedStream ;
@@ -160,7 +168,11 @@ public static async Task<T> LoadAsync<T>(Stream input,
160
168
CancellationToken token = default ) where T : IOpenApiElement
161
169
{
162
170
Utils . CheckArgumentNull ( openApiDocument ) ;
171
+ #if NET6_0_OR_GREATER
172
+ ArgumentNullException . ThrowIfNull ( input ) ;
173
+ #else
163
174
if ( input is null ) throw new ArgumentNullException ( nameof ( input ) ) ;
175
+ #endif
164
176
if ( input is MemoryStream memoryStream )
165
177
{
166
178
return Load < T > ( memoryStream , version , format , openApiDocument , out var _ , settings ) ;
@@ -185,7 +197,11 @@ public static ReadResult Parse(string input,
185
197
string format = null ,
186
198
OpenApiReaderSettings settings = null )
187
199
{
188
- if ( input is null ) throw new ArgumentNullException ( nameof ( input ) ) ;
200
+ #if NET6_0_OR_GREATER
201
+ ArgumentException . ThrowIfNullOrEmpty ( input ) ;
202
+ #else
203
+ if ( string . IsNullOrEmpty ( input ) ) throw new ArgumentNullException ( nameof ( input ) ) ;
204
+ #endif
189
205
format ??= InspectInputFormat ( input ) ;
190
206
settings ??= new OpenApiReaderSettings ( ) ;
191
207
@@ -212,7 +228,11 @@ public static T Parse<T>(string input,
212
228
string format = null ,
213
229
OpenApiReaderSettings settings = null ) where T : IOpenApiElement
214
230
{
215
- if ( input is null ) throw new ArgumentNullException ( nameof ( input ) ) ;
231
+ #if NET6_0_OR_GREATER
232
+ ArgumentException . ThrowIfNullOrEmpty ( input ) ;
233
+ #else
234
+ if ( string . IsNullOrEmpty ( input ) ) throw new ArgumentNullException ( nameof ( input ) ) ;
235
+ #endif
216
236
format ??= InspectInputFormat ( input ) ;
217
237
settings ??= new OpenApiReaderSettings ( ) ;
218
238
using var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( input ) ) ;
@@ -325,8 +345,12 @@ private static string InspectInputFormat(string input)
325
345
326
346
private static string InspectStreamFormat ( Stream stream )
327
347
{
328
- if ( stream == null ) throw new ArgumentNullException ( nameof ( stream ) ) ;
329
-
348
+ #if NET6_0_OR_GREATER
349
+ ArgumentNullException . ThrowIfNull ( stream ) ;
350
+ #else
351
+ if ( stream is null ) throw new ArgumentNullException ( nameof ( stream ) ) ;
352
+ #endif
353
+
330
354
long initialPosition = stream . Position ;
331
355
int firstByte = stream . ReadByte ( ) ;
332
356
0 commit comments