Switch to compiler-tester
[mono.git] / mcs / class / corlib / System.Reflection / ParameterInfo.cs
1 // System.Reflection.ParameterInfo
2 //
3 // Sean MacIsaac (macisaac@ximian.com)
4 //
5 // (C) 2001 Ximian, Inc.
6
7 //
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
9 //
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:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
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.
28 //
29
30 using System.Reflection.Emit;
31 using System.Runtime.CompilerServices;
32 using System.Runtime.InteropServices;
33
34 namespace System.Reflection
35 {
36 #if NET_2_0
37         [ComVisible (true)]
38         [ClassInterfaceAttribute (ClassInterfaceType.None)]
39         [ComDefaultInterfaceAttribute (typeof (_ParameterInfo))]
40 #endif
41         [Serializable]
42         public class ParameterInfo : ICustomAttributeProvider
43         {
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;
51
52                 protected ParameterInfo () {
53                 }
54
55                 internal ParameterInfo (ParameterBuilder pb, Type type, MemberInfo member, int position) {
56                         this.ClassImpl = type;
57                         this.MemberImpl = member;
58                         if (pb != null) {
59                                 this.NameImpl = pb.Name;
60                                 this.PositionImpl = pb.Position - 1;    // ParameterInfo.Position is zero-based
61                                 this.AttrsImpl = (ParameterAttributes) pb.Attributes;
62                         } else {
63                                 this.NameImpl = "";
64                                 this.PositionImpl = position - 1;
65                                 this.AttrsImpl = ParameterAttributes.None;
66                         }
67                 }
68
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;
73                         this.NameImpl = "";
74                         this.PositionImpl = -1; // since parameter positions are zero-based, return type pos is -1
75                         this.AttrsImpl = ParameterAttributes.Retval;
76                 }
77                 
78                 public virtual Type ParameterType {
79                         get {return ClassImpl;}
80                 }
81                 public virtual ParameterAttributes Attributes {
82                         get {return AttrsImpl;}
83                 }
84                 public virtual object DefaultValue {
85                         get {return DefaultValueImpl;}
86                 }
87
88                 public bool IsIn {
89                         get {return (AttrsImpl & ParameterAttributes.In) != 0;}
90                 }
91
92                 public bool IsLcid {
93                         get {return (AttrsImpl & ParameterAttributes.Lcid) != 0;}
94                 }
95
96                 public bool IsOptional {
97                         get {return (AttrsImpl & ParameterAttributes.Optional) != 0;}
98                 }
99
100                 public bool IsOut {
101                         get {return (AttrsImpl & ParameterAttributes.Out) != 0;}
102                 }
103
104                 public bool IsRetval {
105                         get {return (AttrsImpl & ParameterAttributes.Retval) != 0;}
106                 }
107
108                 public virtual MemberInfo Member {
109                         get {return MemberImpl;}
110                 }
111
112                 public virtual string Name {
113                         get {return NameImpl;}
114                 }
115
116                 public virtual int Position {
117                         get {return PositionImpl;}
118                 }
119
120 #if NET_2_0 || BOOTSTRAP_NET_2_0
121                 public
122 #else
123                 internal
124 #endif
125                 virtual extern int MetadataToken {
126                         [MethodImplAttribute (MethodImplOptions.InternalCall)]
127                         get;
128                 }
129
130                 public virtual object[] GetCustomAttributes (bool inherit)
131                 {
132                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
133                 }
134
135                 public virtual object[] GetCustomAttributes (Type attributeType, bool inherit)
136                 {
137                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
138                 }
139
140                 public virtual bool IsDefined( Type attributeType, bool inherit) {
141                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
142                 }
143
144                 internal object[] GetPseudoCustomAttributes () {
145                         int count = 0;
146
147                         if (IsIn)
148                                 count ++;
149                         if (IsOut)
150                                 count ++;
151                         if (IsOptional)
152                                 count ++;
153                         if (marshalAs != null)
154                                 count ++;
155
156                         if (count == 0)
157                                 return null;
158                         object[] attrs = new object [count];
159                         count = 0;
160
161                         if (IsIn)
162                                 attrs [count ++] = new InAttribute ();
163                         if (IsOptional)
164                                 attrs [count ++] = new OptionalAttribute ();
165                         if (IsOut)
166                                 attrs [count ++] = new OutAttribute ();
167
168                         if (marshalAs != null)
169                                 attrs [count ++] = marshalAs.ToMarshalAsAttribute ();
170
171                         return attrs;
172                 }                       
173
174 #if NET_2_0 || BOOTSTRAP_NET_2_0
175                 [Obsolete ("Use ParameterInfo.GetOptionalCustomModifiers().")]
176                 public virtual Type[] OptionalCustomModifiers {
177                         get {
178                                 return GetOptionalCustomModifiers ();
179                         }
180                 }
181
182                 [Obsolete ("Use ParameterInfo.GetRequiredCustomModifiers().")]
183                 public virtual Type[] RequiredCustomModifiers {
184                         get {
185                                 return GetRequiredCustomModifiers ();
186                         }
187                 }
188
189                 [MonoTODO]
190                 public virtual Type[] GetOptionalCustomModifiers () {
191                         throw new NotImplementedException ();
192                 }
193
194                 [MonoTODO]
195                 public virtual Type[] GetRequiredCustomModifiers () {
196                         throw new NotImplementedException ();
197                 }
198
199                 [MonoTODO]
200                 public virtual object RawDefaultValue {
201                         get {
202                                 throw new NotImplementedException ();
203                         }
204                 }
205 #endif
206         }
207 }