1 // System.Reflection.ParameterInfo
3 // Sean MacIsaac (macisaac@ximian.com)
5 // (C) 2001 Ximian, Inc.
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Reflection.Emit;
31 using System.Runtime.CompilerServices;
32 using System.Runtime.InteropServices;
34 namespace System.Reflection
38 [ClassInterfaceAttribute (ClassInterfaceType.None)]
39 [ComDefaultInterfaceAttribute (typeof (_ParameterInfo))]
42 public class ParameterInfo : ICustomAttributeProvider
44 protected Type ClassImpl;
45 protected object DefaultValueImpl;
46 protected MemberInfo MemberImpl;
47 protected string NameImpl;
48 protected int PositionImpl;
49 protected ParameterAttributes AttrsImpl;
50 private UnmanagedMarshal marshalAs;
52 protected ParameterInfo () {
55 internal ParameterInfo (ParameterBuilder pb, Type type, MemberInfo member, int position) {
56 this.ClassImpl = type;
57 this.MemberImpl = member;
59 this.NameImpl = pb.Name;
60 this.PositionImpl = pb.Position - 1; // ParameterInfo.Position is zero-based
61 this.AttrsImpl = (ParameterAttributes) pb.Attributes;
64 this.PositionImpl = position - 1;
65 this.AttrsImpl = ParameterAttributes.None;
69 /* to build a ParameterInfo for the return type of a method */
70 internal ParameterInfo (Type type, MemberInfo member) {
71 this.ClassImpl = type;
72 this.MemberImpl = member;
74 this.PositionImpl = -1; // since parameter positions are zero-based, return type pos is -1
75 this.AttrsImpl = ParameterAttributes.Retval;
78 public virtual Type ParameterType {
79 get {return ClassImpl;}
81 public virtual ParameterAttributes Attributes {
82 get {return AttrsImpl;}
84 public virtual object DefaultValue {
85 get {return DefaultValueImpl;}
89 get {return (AttrsImpl & ParameterAttributes.In) != 0;}
93 get {return (AttrsImpl & ParameterAttributes.Lcid) != 0;}
96 public bool IsOptional {
97 get {return (AttrsImpl & ParameterAttributes.Optional) != 0;}
101 get {return (AttrsImpl & ParameterAttributes.Out) != 0;}
104 public bool IsRetval {
105 get {return (AttrsImpl & ParameterAttributes.Retval) != 0;}
108 public virtual MemberInfo Member {
109 get {return MemberImpl;}
112 public virtual string Name {
113 get {return NameImpl;}
116 public virtual int Position {
117 get {return PositionImpl;}
120 #if NET_2_0 || BOOTSTRAP_NET_2_0
125 virtual extern int MetadataToken {
126 [MethodImplAttribute (MethodImplOptions.InternalCall)]
130 public virtual object[] GetCustomAttributes (bool inherit)
132 return MonoCustomAttrs.GetCustomAttributes (this, inherit);
135 public virtual object[] GetCustomAttributes (Type attributeType, bool inherit)
137 return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
140 public virtual bool IsDefined( Type attributeType, bool inherit) {
141 return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
144 internal object[] GetPseudoCustomAttributes () {
153 if (marshalAs != null)
158 object[] attrs = new object [count];
162 attrs [count ++] = new InAttribute ();
164 attrs [count ++] = new OptionalAttribute ();
166 attrs [count ++] = new OutAttribute ();
168 if (marshalAs != null)
169 attrs [count ++] = marshalAs.ToMarshalAsAttribute ();
174 #if NET_2_0 || BOOTSTRAP_NET_2_0
175 [Obsolete ("Use ParameterInfo.GetOptionalCustomModifiers().")]
176 public virtual Type[] OptionalCustomModifiers {
178 return GetOptionalCustomModifiers ();
182 [Obsolete ("Use ParameterInfo.GetRequiredCustomModifiers().")]
183 public virtual Type[] RequiredCustomModifiers {
185 return GetRequiredCustomModifiers ();
190 public virtual Type[] GetOptionalCustomModifiers () {
191 throw new NotImplementedException ();
195 public virtual Type[] GetRequiredCustomModifiers () {
196 throw new NotImplementedException ();
200 public virtual object RawDefaultValue {
202 throw new NotImplementedException ();