Skip to content

Commit 970a74c

Browse files
committed
Simplify null check by using a coalescing operator
1 parent f381fb7 commit 970a74c

12 files changed

+14
-50
lines changed

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,7 @@ public void Serialize(IOpenApiWriter writer)
199199
/// </summary>
200200
public void SerializeAsV2(IOpenApiWriter writer)
201201
{
202-
if (writer == null)
203-
{
204-
throw Error.ArgumentNull(nameof(writer));
205-
}
202+
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
206203

207204
writer.WriteStartObject();
208205

src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ public void Serialize(IOpenApiWriter writer)
8181
/// </summary>
8282
public void SerializeAsV2(IOpenApiWriter writer)
8383
{
84-
if (writer == null)
85-
{
86-
throw Error.ArgumentNull(nameof(writer));
87-
}
84+
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
8885

8986
writer.WriteStartObject();
9087

src/Microsoft.OpenApi/Models/OpenApiHeader.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,7 @@ public void SerializeAsV3WithoutReference(IOpenApiWriter writer)
222222
/// </summary>
223223
public void SerializeAsV2(IOpenApiWriter writer)
224224
{
225-
if (writer == null)
226-
{
227-
throw Error.ArgumentNull(nameof(writer));
228-
}
225+
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
229226

230227
var target = this;
231228

src/Microsoft.OpenApi/Models/OpenApiInfo.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ public void Serialize(IOpenApiWriter writer)
130130
/// </summary>
131131
public void SerializeAsV2(IOpenApiWriter writer)
132132
{
133-
if (writer == null)
134-
{
135-
throw Error.ArgumentNull(nameof(writer));
136-
}
133+
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
137134

138135
writer.WriteStartObject();
139136

src/Microsoft.OpenApi/Models/OpenApiOperation.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,7 @@ public void Serialize(IOpenApiWriter writer)
209209
/// </summary>
210210
public void SerializeAsV2(IOpenApiWriter writer)
211211
{
212-
if (writer == null)
213-
{
214-
throw Error.ArgumentNull(nameof(writer));
215-
}
212+
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
216213

217214
writer.WriteStartObject();
218215

src/Microsoft.OpenApi/Models/OpenApiParameter.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,7 @@ public void SerializeAsV3WithoutReference(IOpenApiWriter writer)
284284
/// </summary>
285285
public void SerializeAsV2(IOpenApiWriter writer)
286286
{
287-
if (writer == null)
288-
{
289-
throw Error.ArgumentNull(nameof(writer));
290-
}
287+
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
291288

292289
var target = this;
293290
if (Reference != null)

src/Microsoft.OpenApi/Models/OpenApiPathItem.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
@@ -146,10 +146,7 @@ public OpenApiPathItem GetEffective(OpenApiDocument doc)
146146
/// </summary>
147147
public void SerializeAsV2(IOpenApiWriter writer)
148148
{
149-
if (writer == null)
150-
{
151-
throw Error.ArgumentNull(nameof(writer));
152-
}
149+
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
153150

154151
var target = this;
155152

src/Microsoft.OpenApi/Models/OpenApiResponse.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
@@ -157,10 +157,7 @@ public void SerializeAsV3WithoutReference(IOpenApiWriter writer)
157157
/// </summary>
158158
public void SerializeAsV2(IOpenApiWriter writer)
159159
{
160-
if (writer == null)
161-
{
162-
throw Error.ArgumentNull(nameof(writer));
163-
}
160+
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
164161

165162
var target = this;
166163

src/Microsoft.OpenApi/Models/OpenApiSchema.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,7 @@ internal void SerializeAsV2(
510510
ISet<string> parentRequiredProperties,
511511
string propertyName)
512512
{
513-
if (writer == null)
514-
{
515-
throw Error.ArgumentNull(nameof(writer));
516-
}
513+
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
517514

518515
var settings = writer.GetSettings();
519516
var target = this;

src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ public void Serialize(IOpenApiWriter writer)
8686
/// </summary>
8787
public void SerializeAsV2(IOpenApiWriter writer)
8888
{
89-
if (writer == null)
90-
{
91-
throw Error.ArgumentNull(nameof(writer));
92-
}
89+
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
9390

9491
writer.WriteStartObject();
9592

0 commit comments

Comments
 (0)