ArrayExt.cs 603 B

1234567891011121314151617181920212223242526
  1. using System.Runtime.CompilerServices;
  2. namespace System
  3. {
  4. internal static class ArrayExt
  5. {
  6. private static class EmptyArray<T>
  7. {
  8. public static readonly T[] Value;
  9. static EmptyArray()
  10. {
  11. Value = new T[0];
  12. }
  13. }
  14. #if NETSTANDARD
  15. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  16. public static T[] Empty<T>() => Array.Empty<T>();
  17. #else
  18. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  19. public static T[] Empty<T>() => EmptyArray<T>.Value;
  20. #endif
  21. }
  22. }