Empty.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // Author:
  3. // Jb Evain (jbevain@gmail.com)
  4. //
  5. // Copyright (c) 2008 - 2015 Jb Evain
  6. // Copyright (c) 2008 - 2011 Novell, Inc.
  7. //
  8. // Licensed under the MIT/X11 license.
  9. //
  10. using System;
  11. using ILRuntime.Mono.Collections.Generic;
  12. namespace ILRuntime.Mono {
  13. static class Empty<T> {
  14. public static readonly T [] Array = new T [0];
  15. }
  16. class ArgumentNullOrEmptyException : ArgumentException {
  17. public ArgumentNullOrEmptyException (string paramName)
  18. : base ("Argument null or empty", paramName)
  19. {
  20. }
  21. }
  22. }
  23. namespace ILRuntime.Mono.Cecil {
  24. static partial class Mixin {
  25. public static bool IsNullOrEmpty<T> (this T [] self)
  26. {
  27. return self == null || self.Length == 0;
  28. }
  29. public static bool IsNullOrEmpty<T> (this Collection<T> self)
  30. {
  31. return self == null || self.size == 0;
  32. }
  33. public static T [] Resize<T> (this T [] self, int length)
  34. {
  35. Array.Resize (ref self, length);
  36. return self;
  37. }
  38. public static T [] Add<T> (this T [] self, T item)
  39. {
  40. if (self == null) {
  41. self = new [] { item };
  42. return self;
  43. }
  44. self = self.Resize (self.Length + 1);
  45. self [self.Length - 1] = item;
  46. return self;
  47. }
  48. }
  49. }