Skip to content

Commit ae5f451

Browse files
committed
Fixing GetEnumerableElementType bug
1 parent f561bdd commit ae5f451

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

ReadableExpressions.UnitTests/Extensions/WhenAccessingTypeInformation.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public void ShouldEvaluateANonGenericListAsEnumerable()
3030
typeof(IList).IsEnumerable().ShouldBeTrue();
3131
}
3232

33+
[Fact]
34+
public void ShouldEvaluateANonGenericEnumerableAsEnumerable()
35+
{
36+
typeof(IEnumerable).IsEnumerable().ShouldBeTrue();
37+
}
38+
3339
[Fact]
3440
public void ShouldNotEvaluateAStringAsEnumerable()
3541
{

ReadableExpressions/Extensions/PublicTypeExtensions.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,14 @@ public static Type GetEnumerableElementType(this Type enumerableType)
345345

346346
if (enumerableType.IsGenericType())
347347
{
348-
return InternalEnumerableExtensions.Last(enumerableType.GetGenericTypeArguments());
348+
return enumerableType.GetGenericTypeArguments().Last();
349349
}
350350

351-
var enumerableInterfaceType = InternalEnumerableExtensions.FirstOrDefault(enumerableType
352-
.GetAllInterfaces(), interfaceType => interfaceType.IsClosedTypeOf(typeof(IEnumerable<>)));
351+
var enumerableInterfaceType = enumerableType
352+
.GetAllInterfaces()
353+
.FirstOrDefault(interfaceType => interfaceType.IsClosedTypeOf(typeof(IEnumerable<>)));
353354

354-
return InternalEnumerableExtensions.First(enumerableInterfaceType?.GetGenericTypeArguments()) ?? typeof(object);
355+
return enumerableInterfaceType?.GetGenericTypeArguments().First() ?? typeof(object);
355356
}
356357

357358
/// <summary>
@@ -360,19 +361,15 @@ public static Type GetEnumerableElementType(this Type enumerableType)
360361
/// <param name="type">The type for which to make the determination.</param>
361362
/// <returns>True if the given <paramref name="type"/> can be null, otherwise false.</returns>
362363
public static bool CanBeNull(this Type type)
363-
{
364-
return type.IsClass() || type.IsInterface() || type.IsNullableType();
365-
}
364+
=> type.IsClass() || type.IsInterface() || type.IsNullableType();
366365

367366
/// <summary>
368367
/// Returns a value indicating if the given <paramref name="type"/> is a Nullable{T}.
369368
/// </summary>
370369
/// <param name="type">The type for which to make the determination.</param>
371370
/// <returns>True if the given <paramref name="type"/> is a Nullable{T}, otherwise false.</returns>
372371
public static bool IsNullableType(this Type type)
373-
{
374-
return Nullable.GetUnderlyingType(type) != null;
375-
}
372+
=> Nullable.GetUnderlyingType(type) != null;
376373

377374
/// <summary>
378375
/// Gets the underlying non-nullable Type of this <paramref name="type"/>, or returns this

0 commit comments

Comments
 (0)