ParameterInfo.cs 4.8 KB

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