/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
- //
- // Author:
- // Jb Evain (jbevain@gmail.com)
- //
- // Copyright (c) 2008 - 2015 Jb Evain
- // Copyright (c) 2008 - 2011 Novell, Inc.
- //
- // Licensed under the MIT/X11 license.
- //
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Mono.Cecil.Rocks {
- #if INSIDE_ROCKS
- public
- #endif
- static class TypeDefinitionRocks {
- public static IEnumerable<MethodDefinition> GetConstructors (this TypeDefinition self)
- {
- if (self == null)
- throw new ArgumentNullException ("self");
- if (!self.HasMethods)
- return Empty<MethodDefinition>.Array;
- return self.Methods.Where (method => method.IsConstructor);
- }
- public static MethodDefinition GetStaticConstructor (this TypeDefinition self)
- {
- if (self == null)
- throw new ArgumentNullException ("self");
- if (!self.HasMethods)
- return null;
- return self.GetConstructors ().FirstOrDefault (ctor => ctor.IsStatic);
- }
- public static IEnumerable<MethodDefinition> GetMethods (this TypeDefinition self)
- {
- if (self == null)
- throw new ArgumentNullException ("self");
- if (!self.HasMethods)
- return Empty<MethodDefinition>.Array;
- return self.Methods.Where (method => !method.IsConstructor);
- }
- public static TypeReference GetEnumUnderlyingType (this TypeDefinition self)
- {
- if (self == null)
- throw new ArgumentNullException ("self");
- if (!self.IsEnum)
- throw new ArgumentException ();
- return Mixin.GetEnumUnderlyingType (self);
- }
- }
- }