ParameterInfo.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. namespace System.Reflection
  30. {
  31. [Serializable]
  32. public class ParameterInfo : ICustomAttributeProvider
  33. {
  34. protected Type ClassImpl;
  35. protected object DefaultValueImpl;
  36. protected MemberInfo MemberImpl;
  37. protected string NameImpl;
  38. protected int PositionImpl;
  39. protected ParameterAttributes AttrsImpl;
  40. protected ParameterInfo () {
  41. }
  42. internal ParameterInfo (ParameterBuilder pb, Type type, MemberInfo member, int position) {
  43. this.ClassImpl = type;
  44. this.MemberImpl = member;
  45. if (pb != null) {
  46. this.NameImpl = pb.Name;
  47. this.PositionImpl = pb.Position - 1; // ParameterInfo.Position is zero-based
  48. this.AttrsImpl = (ParameterAttributes) pb.Attributes;
  49. } else {
  50. this.NameImpl = "";
  51. this.PositionImpl = position - 1;
  52. this.AttrsImpl = ParameterAttributes.None;
  53. }
  54. }
  55. /* to build a ParameterInfo for the return type of a method */
  56. internal ParameterInfo (Type type, MemberInfo member) {
  57. this.ClassImpl = type;
  58. this.MemberImpl = member;
  59. this.NameImpl = "";
  60. this.PositionImpl = -1; // since parameter positions are zero-based, return type pos is -1
  61. this.AttrsImpl = ParameterAttributes.Retval;
  62. }
  63. public virtual Type ParameterType {
  64. get {return ClassImpl;}
  65. }
  66. public virtual ParameterAttributes Attributes {
  67. get {return AttrsImpl;}
  68. }
  69. public virtual object DefaultValue {
  70. get {return DefaultValueImpl;}
  71. }
  72. public bool IsIn {
  73. get {return (AttrsImpl & ParameterAttributes.In) != 0;}
  74. }
  75. public bool IsLcid {
  76. get {return (AttrsImpl & ParameterAttributes.Lcid) != 0;}
  77. }
  78. public bool IsOptional {
  79. get {return (AttrsImpl & ParameterAttributes.Optional) != 0;}
  80. }
  81. public bool IsOut {
  82. get {return (AttrsImpl & ParameterAttributes.Out) != 0;}
  83. }
  84. public bool IsRetval {
  85. get {return (AttrsImpl & ParameterAttributes.Retval) != 0;}
  86. }
  87. public virtual MemberInfo Member {
  88. get {return MemberImpl;}
  89. }
  90. public virtual string Name {
  91. get {return NameImpl;}
  92. }
  93. public virtual int Position {
  94. get {return PositionImpl;}
  95. }
  96. public virtual object[] GetCustomAttributes (bool inherit)
  97. {
  98. return MonoCustomAttrs.GetCustomAttributes (this, inherit);
  99. }
  100. public virtual object[] GetCustomAttributes (Type attributeType, bool inherit)
  101. {
  102. return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
  103. }
  104. public virtual bool IsDefined( Type attributeType, bool inherit) {
  105. return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
  106. }
  107. }
  108. }