/rocks/Mono.Cecil.Rocks/TypeReferenceRocks.cs

http://github.com/jbevain/cecil · C# · 89 lines · 62 code · 18 blank · 9 comment · 11 complexity · 1fbf78be03dc1ee023450b3bd1556bf3 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 TypeReferenceRocks {
  18. public static ArrayType MakeArrayType (this TypeReference self)
  19. {
  20. return new ArrayType (self);
  21. }
  22. public static ArrayType MakeArrayType (this TypeReference self, int rank)
  23. {
  24. if (rank == 0)
  25. throw new ArgumentOutOfRangeException ("rank");
  26. var array = new ArrayType (self);
  27. for (int i = 1; i < rank; i++)
  28. array.Dimensions.Add (new ArrayDimension ());
  29. return array;
  30. }
  31. public static PointerType MakePointerType (this TypeReference self)
  32. {
  33. return new PointerType (self);
  34. }
  35. public static ByReferenceType MakeByReferenceType (this TypeReference self)
  36. {
  37. return new ByReferenceType (self);
  38. }
  39. public static OptionalModifierType MakeOptionalModifierType (this TypeReference self, TypeReference modifierType)
  40. {
  41. return new OptionalModifierType (modifierType, self);
  42. }
  43. public static RequiredModifierType MakeRequiredModifierType (this TypeReference self, TypeReference modifierType)
  44. {
  45. return new RequiredModifierType (modifierType, self);
  46. }
  47. public static GenericInstanceType MakeGenericInstanceType (this TypeReference self, params TypeReference [] arguments)
  48. {
  49. if (self == null)
  50. throw new ArgumentNullException ("self");
  51. if (arguments == null)
  52. throw new ArgumentNullException ("arguments");
  53. if (arguments.Length == 0)
  54. throw new ArgumentException ();
  55. if (self.GenericParameters.Count != arguments.Length)
  56. throw new ArgumentException ();
  57. var instance = new GenericInstanceType (self, arguments.Length);
  58. foreach (var argument in arguments)
  59. instance.GenericArguments.Add (argument);
  60. return instance;
  61. }
  62. public static PinnedType MakePinnedType (this TypeReference self)
  63. {
  64. return new PinnedType (self);
  65. }
  66. public static SentinelType MakeSentinelType (this TypeReference self)
  67. {
  68. return new SentinelType (self);
  69. }
  70. }
  71. }