ParameterInfo.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // System.Reflection.ParameterInfo
  2. //
  3. // Sean MacIsaac ([email protected])
  4. //
  5. // (C) 2001 Ximian, Inc.
  6. //
  7. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  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.Reflection.Emit;
  29. using System.Runtime.CompilerServices;
  30. using System.Runtime.InteropServices;
  31. namespace System.Reflection
  32. {
  33. #if NET_2_0
  34. [ComVisible (true)]
  35. #endif
  36. [Serializable]
  37. public class ParameterInfo : ICustomAttributeProvider
  38. {
  39. protected Type ClassImpl;
  40. protected object DefaultValueImpl;
  41. protected MemberInfo MemberImpl;
  42. protected string NameImpl;
  43. protected int PositionImpl;
  44. protected ParameterAttributes AttrsImpl;
  45. private UnmanagedMarshal marshalAs;
  46. protected ParameterInfo () {
  47. }
  48. internal ParameterInfo (ParameterBuilder pb, Type type, MemberInfo member, int position) {
  49. this.ClassImpl = type;
  50. this.MemberImpl = member;
  51. if (pb != null) {
  52. this.NameImpl = pb.Name;
  53. this.PositionImpl = pb.Position - 1; // ParameterInfo.Position is zero-based
  54. this.AttrsImpl = (ParameterAttributes) pb.Attributes;
  55. } else {
  56. this.NameImpl = "";
  57. this.PositionImpl = position - 1;
  58. this.AttrsImpl = ParameterAttributes.None;
  59. }
  60. }
  61. /* to build a ParameterInfo for the return type of a method */
  62. internal ParameterInfo (Type type, MemberInfo member) {
  63. this.ClassImpl = type;
  64. this.MemberImpl = member;
  65. this.NameImpl = "";
  66. this.PositionImpl = -1; // since parameter positions are zero-based, return type pos is -1
  67. this.AttrsImpl = ParameterAttributes.Retval;
  68. }
  69. public virtual Type ParameterType {
  70. get {return ClassImpl;}
  71. }
  72. public virtual ParameterAttributes Attributes {
  73. get {return AttrsImpl;}
  74. }
  75. public virtual object DefaultValue {
  76. get {return DefaultValueImpl;}
  77. }
  78. public bool IsIn {
  79. get {return (AttrsImpl & ParameterAttributes.In) != 0;}
  80. }
  81. public bool IsLcid {
  82. get {return (AttrsImpl & ParameterAttributes.Lcid) != 0;}
  83. }
  84. public bool IsOptional {
  85. get {return (AttrsImpl & ParameterAttributes.Optional) != 0;}
  86. }
  87. public bool IsOut {
  88. get {return (AttrsImpl & ParameterAttributes.Out) != 0;}
  89. }
  90. public bool IsRetval {
  91. get {return (AttrsImpl & ParameterAttributes.Retval) != 0;}
  92. }
  93. public virtual MemberInfo Member {
  94. get {return MemberImpl;}
  95. }
  96. public virtual string Name {
  97. get {return NameImpl;}
  98. }
  99. public virtual int Position {
  100. get {return PositionImpl;}
  101. }
  102. #if NET_2_0 || BOOTSTRAP_NET_2_0
  103. public
  104. #else
  105. internal
  106. #endif
  107. virtual extern int MetadataToken {
  108. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  109. get;
  110. }
  111. public virtual object[] GetCustomAttributes (bool inherit)
  112. {
  113. return MonoCustomAttrs.GetCustomAttributes (this, inherit);
  114. }
  115. public virtual object[] GetCustomAttributes (Type attributeType, bool inherit)
  116. {
  117. return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
  118. }
  119. public virtual bool IsDefined( Type attributeType, bool inherit) {
  120. return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
  121. }
  122. internal object[] GetPseudoCustomAttributes () {
  123. int count = 0;
  124. if (IsIn)
  125. count ++;
  126. if (IsOut)
  127. count ++;
  128. if (IsOptional)
  129. count ++;
  130. if (marshalAs != null)
  131. count ++;
  132. if (count == 0)
  133. return null;
  134. object[] attrs = new object [count];
  135. count = 0;
  136. if (IsIn)
  137. attrs [count ++] = new InAttribute ();
  138. if (IsOptional)
  139. attrs [count ++] = new OptionalAttribute ();
  140. if (IsOut)
  141. attrs [count ++] = new OutAttribute ();
  142. if (marshalAs != null)
  143. attrs [count ++] = marshalAs.ToMarshalAsAttribute ();
  144. return attrs;
  145. }
  146. #if NET_2_0 || BOOTSTRAP_NET_2_0
  147. [MonoTODO]
  148. public virtual Type[] OptionalCustomModifiers {
  149. get {
  150. throw new NotImplementedException ();
  151. }
  152. }
  153. [MonoTODO]
  154. public virtual Type[] RequiredCustomModifiers {
  155. get {
  156. throw new NotImplementedException ();
  157. }
  158. }
  159. #endif
  160. }
  161. }