/Mono.Cecil/Modifiers.cs

http://github.com/jbevain/cecil · C# · 112 lines · 78 code · 25 blank · 9 comment · 6 complexity · 00e31b5a0b259fa08fb188194f023461 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 MD = Mono.Cecil.Metadata;
  12. namespace Mono.Cecil {
  13. public interface IModifierType {
  14. TypeReference ModifierType { get; }
  15. TypeReference ElementType { get; }
  16. }
  17. public sealed class OptionalModifierType : TypeSpecification, IModifierType {
  18. TypeReference modifier_type;
  19. public TypeReference ModifierType {
  20. get { return modifier_type; }
  21. set { modifier_type = value; }
  22. }
  23. public override string Name {
  24. get { return base.Name + Suffix; }
  25. }
  26. public override string FullName {
  27. get { return base.FullName + Suffix; }
  28. }
  29. string Suffix {
  30. get { return " modopt(" + modifier_type + ")"; }
  31. }
  32. public override bool IsValueType {
  33. get { return false; }
  34. set { throw new InvalidOperationException (); }
  35. }
  36. public override bool IsOptionalModifier {
  37. get { return true; }
  38. }
  39. public override bool ContainsGenericParameter {
  40. get { return modifier_type.ContainsGenericParameter || base.ContainsGenericParameter; }
  41. }
  42. public OptionalModifierType (TypeReference modifierType, TypeReference type)
  43. : base (type)
  44. {
  45. if (modifierType == null)
  46. throw new ArgumentNullException (Mixin.Argument.modifierType.ToString ());
  47. Mixin.CheckType (type);
  48. this.modifier_type = modifierType;
  49. this.etype = MD.ElementType.CModOpt;
  50. }
  51. }
  52. public sealed class RequiredModifierType : TypeSpecification, IModifierType {
  53. TypeReference modifier_type;
  54. public TypeReference ModifierType {
  55. get { return modifier_type; }
  56. set { modifier_type = value; }
  57. }
  58. public override string Name {
  59. get { return base.Name + Suffix; }
  60. }
  61. public override string FullName {
  62. get { return base.FullName + Suffix; }
  63. }
  64. string Suffix {
  65. get { return " modreq(" + modifier_type + ")"; }
  66. }
  67. public override bool IsValueType {
  68. get { return false; }
  69. set { throw new InvalidOperationException (); }
  70. }
  71. public override bool IsRequiredModifier {
  72. get { return true; }
  73. }
  74. public override bool ContainsGenericParameter {
  75. get { return modifier_type.ContainsGenericParameter || base.ContainsGenericParameter; }
  76. }
  77. public RequiredModifierType (TypeReference modifierType, TypeReference type)
  78. : base (type)
  79. {
  80. if (modifierType == null)
  81. throw new ArgumentNullException (Mixin.Argument.modifierType.ToString ());
  82. Mixin.CheckType (type);
  83. this.modifier_type = modifierType;
  84. this.etype = MD.ElementType.CModReqD;
  85. }
  86. }
  87. }