PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/rocks/Mono.Cecil.Rocks/TypeDefinitionRocks.cs

http://github.com/jbevain/cecil
C# | 65 lines | 42 code | 14 blank | 9 comment | 12 complexity | 8bc5354de7714e9dea73f1fd728df4b7 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 System.Collections.Generic;
13using System.Linq;
14
15namespace Mono.Cecil.Rocks {
16
17#if INSIDE_ROCKS
18	public
19#endif
20	static class TypeDefinitionRocks {
21
22		public static IEnumerable<MethodDefinition> GetConstructors (this TypeDefinition self)
23		{
24			if (self == null)
25				throw new ArgumentNullException ("self");
26
27			if (!self.HasMethods)
28				return Empty<MethodDefinition>.Array;
29
30			return self.Methods.Where (method => method.IsConstructor);
31		}
32
33		public static MethodDefinition GetStaticConstructor (this TypeDefinition self)
34		{
35			if (self == null)
36				throw new ArgumentNullException ("self");
37
38			if (!self.HasMethods)
39				return null;
40
41			return self.GetConstructors ().FirstOrDefault (ctor => ctor.IsStatic);
42		}
43
44		public static IEnumerable<MethodDefinition> GetMethods (this TypeDefinition self)
45		{
46			if (self == null)
47				throw new ArgumentNullException ("self");
48
49			if (!self.HasMethods)
50				return Empty<MethodDefinition>.Array;
51
52			return self.Methods.Where (method => !method.IsConstructor);
53		}
54
55		public static TypeReference GetEnumUnderlyingType (this TypeDefinition self)
56		{
57			if (self == null)
58				throw new ArgumentNullException ("self");
59			if (!self.IsEnum)
60				throw new ArgumentException ();
61
62			return Mixin.GetEnumUnderlyingType (self);
63		}
64	}
65}