Hide.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. namespace System.Linq
  9. {
  10. public static partial class EnumerableEx
  11. {
  12. /// <summary>
  13. /// Hides the enumerable sequence object identity.
  14. /// </summary>
  15. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  16. /// <param name="source">Source sequence.</param>
  17. /// <returns>Enumerable sequence with the same behavior as the original, but hiding the source object identity.</returns>
  18. /// <remarks>
  19. /// AsEnumerable doesn't hide the object identity, and simply acts as a cast to the IEnumerable&lt;TSource&gt;
  20. /// interface.
  21. /// </remarks>
  22. public static IEnumerable<TSource> Hide<TSource>(this IEnumerable<TSource> source)
  23. {
  24. if (source == null)
  25. throw new ArgumentNullException(nameof(source));
  26. return source.Hide_();
  27. }
  28. private static IEnumerable<TSource> Hide_<TSource>(this IEnumerable<TSource> source)
  29. {
  30. foreach (var item in source)
  31. yield return item;
  32. }
  33. }
  34. }