Skip to content

Commit b0c6cbc

Browse files
committed
Address PR Comment
Resolve reliance on reflection
1 parent f6b27df commit b0c6cbc

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
// Licensed under the MIT license.
33

44
using System;
5-
using System.Collections;
65
using System.Collections.Generic;
76
using System.Globalization;
87
using System.IO;
9-
using System.Reflection;
108
using System.Threading;
119
using System.Threading.Tasks;
1210
using Microsoft.OpenApi.Exceptions;
@@ -213,13 +211,14 @@ public virtual void WriteValue(bool value)
213211
}
214212

215213
/// <summary>
216-
/// Write hashSet value.
214+
/// Writes an enumerable collection as an array
217215
/// </summary>
218-
/// <param name="value">The HashSet value.</param>
219-
public virtual void WriteHashSet(IEnumerable<object> value)
216+
/// <param name="collection">The enumerable collection to write.</param>
217+
/// <typeparam name="T">The type of elements in the collection.</typeparam>
218+
public virtual void WriteEnumerable<T>(IEnumerable<T> collection)
220219
{
221220
WriteStartArray();
222-
foreach (var item in value)
221+
foreach (var item in collection)
223222
{
224223
WriteValue(item);
225224
}
@@ -280,9 +279,9 @@ public virtual void WriteValue(object value)
280279
{
281280
WriteValue((DateTimeOffset)value);
282281
}
283-
else if (value is IEnumerable<object> hashSet && value.GetType().GetGenericTypeDefinition() == typeof(HashSet<>))
282+
else if (value is IEnumerable<object> enumerable)
284283
{
285-
WriteHashSet(hashSet);
284+
WriteEnumerable(enumerable);
286285
}
287286
else
288287
{

test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,7 @@ namespace Microsoft.OpenApi.Writers
19731973
protected void VerifyCanWritePropertyName(string name) { }
19741974
public abstract void WriteEndArray();
19751975
public abstract void WriteEndObject();
1976-
public virtual void WriteHashSet(System.Collections.Generic.IEnumerable<object> value) { }
1976+
public virtual void WriteEnumerable<T>(System.Collections.Generic.IEnumerable<T> collection) { }
19771977
public virtual void WriteIndentation() { }
19781978
public abstract void WriteNull();
19791979
public abstract void WritePropertyName(string name);

0 commit comments

Comments
 (0)