PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/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
11using System;
12using Mono.Collections.Generic;
13
14namespace Mono {
15
16	static class Empty<T> {
17
18		public static readonly T [] Array = new T [0];
19	}
20
21	class ArgumentNullOrEmptyException : ArgumentException {
22
23		public ArgumentNullOrEmptyException (string paramName)
24			: base ("Argument null or empty", paramName)
25		{
26		}
27	}
28}
29
30namespace Mono.Cecil {
31
32	static partial class Mixin {
33
34		public static bool IsNullOrEmpty<T> (this T [] self)
35		{
36			return self == null || self.Length == 0;
37		}
38
39		public static bool IsNullOrEmpty<T> (this Collection<T> self)
40		{
41			return self == null || self.size == 0;
42		}
43
44		public static T [] Resize<T> (this T [] self, int length)
45		{
46			Array.Resize (ref self, length);
47			return self;
48		}
49
50		public static T [] Add<T> (this T [] self, T item)
51		{
52			if (self == null) {
53				self = new [] { item };
54				return self;
55			}
56
57			self = self.Resize (self.Length + 1);
58			self [self.Length - 1] = item;
59			return self;
60		}
61	}
62}