ParameterDefinition.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 Mono.Collections.Generic;
  11. namespace Mono.Cecil {
  12. public sealed class ParameterDefinition : ParameterReference, ICustomAttributeProvider, IConstantProvider, IMarshalInfoProvider {
  13. ushort attributes;
  14. internal IMethodSignature method;
  15. object constant = Mixin.NotResolved;
  16. Collection<CustomAttribute> custom_attributes;
  17. MarshalInfo marshal_info;
  18. public ParameterAttributes Attributes {
  19. get { return (ParameterAttributes) attributes; }
  20. set { attributes = (ushort) value; }
  21. }
  22. public IMethodSignature Method {
  23. get { return method; }
  24. }
  25. public int Sequence {
  26. get {
  27. if (method == null)
  28. return -1;
  29. return method.HasImplicitThis () ? index + 1 : index;
  30. }
  31. }
  32. public bool HasConstant {
  33. get {
  34. this.ResolveConstant (ref constant, parameter_type.Module);
  35. return constant != Mixin.NoValue;
  36. }
  37. set { if (!value) constant = Mixin.NoValue; }
  38. }
  39. public object Constant {
  40. get { return HasConstant ? constant : null; }
  41. set { constant = value; }
  42. }
  43. public bool HasCustomAttributes {
  44. get {
  45. if (custom_attributes != null)
  46. return custom_attributes.Count > 0;
  47. return this.GetHasCustomAttributes (parameter_type.Module);
  48. }
  49. }
  50. public Collection<CustomAttribute> CustomAttributes {
  51. get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, parameter_type.Module)); }
  52. }
  53. public bool HasMarshalInfo {
  54. get {
  55. if (marshal_info != null)
  56. return true;
  57. return this.GetHasMarshalInfo (parameter_type.Module);
  58. }
  59. }
  60. public MarshalInfo MarshalInfo {
  61. get { return marshal_info ?? (this.GetMarshalInfo (ref marshal_info, parameter_type.Module)); }
  62. set { marshal_info = value; }
  63. }
  64. #region ParameterAttributes
  65. public bool IsIn {
  66. get { return attributes.GetAttributes ((ushort) ParameterAttributes.In); }
  67. set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.In, value); }
  68. }
  69. public bool IsOut {
  70. get { return attributes.GetAttributes ((ushort) ParameterAttributes.Out); }
  71. set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Out, value); }
  72. }
  73. public bool IsLcid {
  74. get { return attributes.GetAttributes ((ushort) ParameterAttributes.Lcid); }
  75. set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Lcid, value); }
  76. }
  77. public bool IsReturnValue {
  78. get { return attributes.GetAttributes ((ushort) ParameterAttributes.Retval); }
  79. set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Retval, value); }
  80. }
  81. public bool IsOptional {
  82. get { return attributes.GetAttributes ((ushort) ParameterAttributes.Optional); }
  83. set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Optional, value); }
  84. }
  85. public bool HasDefault {
  86. get { return attributes.GetAttributes ((ushort) ParameterAttributes.HasDefault); }
  87. set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.HasDefault, value); }
  88. }
  89. public bool HasFieldMarshal {
  90. get { return attributes.GetAttributes ((ushort) ParameterAttributes.HasFieldMarshal); }
  91. set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.HasFieldMarshal, value); }
  92. }
  93. #endregion
  94. internal ParameterDefinition (TypeReference parameterType, IMethodSignature method)
  95. : this (string.Empty, ParameterAttributes.None, parameterType)
  96. {
  97. this.method = method;
  98. }
  99. public ParameterDefinition (TypeReference parameterType)
  100. : this (string.Empty, ParameterAttributes.None, parameterType)
  101. {
  102. }
  103. public ParameterDefinition (string name, ParameterAttributes attributes, TypeReference parameterType)
  104. : base (name, parameterType)
  105. {
  106. this.attributes = (ushort) attributes;
  107. this.token = new MetadataToken (TokenType.Param);
  108. }
  109. public override ParameterDefinition Resolve ()
  110. {
  111. return this;
  112. }
  113. }
  114. }