/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. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. namespace Mono.Cecil.Rocks {
  14. #if INSIDE_ROCKS
  15. public
  16. #endif
  17. static class TypeDefinitionRocks {
  18. public static IEnumerable<MethodDefinition> GetConstructors (this TypeDefinition self)
  19. {
  20. if (self == null)
  21. throw new ArgumentNullException ("self");
  22. if (!self.HasMethods)
  23. return Empty<MethodDefinition>.Array;
  24. return self.Methods.Where (method => method.IsConstructor);
  25. }
  26. public static MethodDefinition GetStaticConstructor (this TypeDefinition self)
  27. {
  28. if (self == null)
  29. throw new ArgumentNullException ("self");
  30. if (!self.HasMethods)
  31. return null;
  32. return self.GetConstructors ().FirstOrDefault (ctor => ctor.IsStatic);
  33. }
  34. public static IEnumerable<MethodDefinition> GetMethods (this TypeDefinition self)
  35. {
  36. if (self == null)
  37. throw new ArgumentNullException ("self");
  38. if (!self.HasMethods)
  39. return Empty<MethodDefinition>.Array;
  40. return self.Methods.Where (method => !method.IsConstructor);
  41. }
  42. public static TypeReference GetEnumUnderlyingType (this TypeDefinition self)
  43. {
  44. if (self == null)
  45. throw new ArgumentNullException ("self");
  46. if (!self.IsEnum)
  47. throw new ArgumentException ();
  48. return Mixin.GetEnumUnderlyingType (self);
  49. }
  50. }
  51. }