/Mono/Empty.cs

http://github.com/jbevain/cecil · C# · 62 lines · 40 code · 13 blank · 9 comment · 8 complexity · 7fc9eaf67b2a10a33be19832bcd64e3c MD5 · raw file

  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 Mono.Collections.Generic;
  12. namespace 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 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. }