/Mono.Cecil/Mono.Cecil/Modifiers.cs

http://github.com/icsharpcode/ILSpy · C# · 137 lines · 83 code · 27 blank · 27 comment · 6 complexity · ef9559449ce5215f80549ef2d94e1d35 MD5 · raw file

  1. //
  2. // Modifiers.cs
  3. //
  4. // Author:
  5. // Jb Evain (jbevain@gmail.com)
  6. //
  7. // Copyright (c) 2008 - 2011 Jb Evain
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using MD = Mono.Cecil.Metadata;
  30. namespace Mono.Cecil {
  31. public interface IModifierType {
  32. TypeReference ModifierType { get; }
  33. TypeReference ElementType { get; }
  34. }
  35. public sealed class OptionalModifierType : TypeSpecification, IModifierType {
  36. TypeReference modifier_type;
  37. public TypeReference ModifierType {
  38. get { return modifier_type; }
  39. set { modifier_type = value; }
  40. }
  41. public override string Name {
  42. get { return base.Name + Suffix; }
  43. }
  44. public override string FullName {
  45. get { return base.FullName + Suffix; }
  46. }
  47. string Suffix {
  48. get { return " modopt(" + modifier_type + ")"; }
  49. }
  50. public override bool IsValueType {
  51. get { return false; }
  52. set { throw new InvalidOperationException (); }
  53. }
  54. public override bool IsOptionalModifier {
  55. get { return true; }
  56. }
  57. internal override bool ContainsGenericParameter {
  58. get { return modifier_type.ContainsGenericParameter || base.ContainsGenericParameter; }
  59. }
  60. public OptionalModifierType (TypeReference modifierType, TypeReference type)
  61. : base (type)
  62. {
  63. Mixin.CheckModifier (modifierType, type);
  64. this.modifier_type = modifierType;
  65. this.etype = MD.ElementType.CModOpt;
  66. }
  67. }
  68. public sealed class RequiredModifierType : TypeSpecification, IModifierType {
  69. TypeReference modifier_type;
  70. public TypeReference ModifierType {
  71. get { return modifier_type; }
  72. set { modifier_type = value; }
  73. }
  74. public override string Name {
  75. get { return base.Name + Suffix; }
  76. }
  77. public override string FullName {
  78. get { return base.FullName + Suffix; }
  79. }
  80. string Suffix {
  81. get { return " modreq(" + modifier_type + ")"; }
  82. }
  83. public override bool IsValueType {
  84. get { return false; }
  85. set { throw new InvalidOperationException (); }
  86. }
  87. public override bool IsRequiredModifier {
  88. get { return true; }
  89. }
  90. internal override bool ContainsGenericParameter {
  91. get { return modifier_type.ContainsGenericParameter || base.ContainsGenericParameter; }
  92. }
  93. public RequiredModifierType (TypeReference modifierType, TypeReference type)
  94. : base (type)
  95. {
  96. Mixin.CheckModifier (modifierType, type);
  97. this.modifier_type = modifierType;
  98. this.etype = MD.ElementType.CModReqD;
  99. }
  100. }
  101. static partial class Mixin {
  102. public static void CheckModifier (TypeReference modifierType, TypeReference type)
  103. {
  104. if (modifierType == null)
  105. throw new ArgumentNullException ("modifierType");
  106. if (type == null)
  107. throw new ArgumentNullException ("type");
  108. }
  109. }
  110. }