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