Skip to content

Commit

Permalink
Avoid casting collection to IEnumerable<T> for private method
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup committed Aug 11, 2023
1 parent d79735a commit 7428fe2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Src/FluentAssertions/Common/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ private static IEnumerable<TAttribute> GetCustomAttributes<TAttribute>(MemberInf
return GetCustomAttributes<TAttribute>(type, inherit).Where(isMatchingAttribute);
}

private static IEnumerable<TAttribute> GetCustomAttributes<TAttribute>(this Type type, bool inherit = false)
private static TAttribute[] GetCustomAttributes<TAttribute>(this Type type, bool inherit = false)
where TAttribute : Attribute
{
return (IEnumerable<TAttribute>)type.GetCustomAttributes(typeof(TAttribute), inherit);
return (TAttribute[])type.GetCustomAttributes(typeof(TAttribute), inherit);
}

private static IEnumerable<TAttribute> GetCustomAttributes<TAttribute>(Type type,
Expand Down
4 changes: 2 additions & 2 deletions Src/FluentAssertions/Specialized/ExceptionAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public ExceptionAssertions<TException> Where(Expression<Func<TException, bool>>
return this;
}

private IEnumerable<Exception> AssertInnerExceptionExactly(Type innerException, string because = "",
private Exception[] AssertInnerExceptionExactly(Type innerException, string because = "",
params object[] becauseArgs)
{
Execute.Assertion
Expand All @@ -219,7 +219,7 @@ private IEnumerable<Exception> AssertInnerExceptionExactly(Type innerException,
return expectedExceptions;
}

private IEnumerable<Exception> AssertInnerExceptions(Type innerException, string because = "",
private Exception[] AssertInnerExceptions(Type innerException, string because = "",
params object[] becauseArgs)
{
Execute.Assertion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public void Dispose() { }

internal class OneTimeEnumerable<T> : IEnumerable<T>
{
private readonly IEnumerable<T> items;
private readonly T[] items;
private int enumerations;

public OneTimeEnumerable(params T[] items) => this.items = items;
Expand All @@ -368,7 +368,7 @@ public IEnumerator<T> GetEnumerator()
throw new InvalidOperationException("OneTimeEnumerable can be enumerated one time only");
}

return items.GetEnumerator();
return items.AsEnumerable().GetEnumerator();
}
}

Expand Down

0 comments on commit 7428fe2

Please sign in to comment.