Merge pull request #216 from ilkerde/master
[mono.git] / mcs / class / IKVM.Reflection / ConstructorInfo.cs
1 /*
2   Copyright (C) 2009 Jeroen Frijters
3
4   This software is provided 'as-is', without any express or implied
5   warranty.  In no event will the authors be held liable for any damages
6   arising from the use of this software.
7
8   Permission is granted to anyone to use this software for any purpose,
9   including commercial applications, and to alter it and redistribute it
10   freely, subject to the following restrictions:
11
12   1. The origin of this software must not be misrepresented; you must not
13      claim that you wrote the original software. If you use this software
14      in a product, an acknowledgment in the product documentation would be
15      appreciated but is not required.
16   2. Altered source versions must be plainly marked as such, and must not be
17      misrepresented as being the original software.
18   3. This notice may not be removed or altered from any source distribution.
19
20   Jeroen Frijters
21   jeroen@frijters.net
22   
23 */
24 using System;
25 using System.Collections.Generic;
26
27 namespace IKVM.Reflection
28 {
29         public abstract class ConstructorInfo : MethodBase
30         {
31                 // prevent external subclasses
32                 internal ConstructorInfo()
33                 {
34                 }
35
36                 public static readonly string ConstructorName = ".ctor";
37                 public static readonly string TypeConstructorName = ".cctor";
38
39                 internal abstract MethodInfo GetMethodInfo();
40
41                 internal override MethodBase BindTypeParameters(Type type)
42                 {
43                         return new ConstructorInfoImpl((MethodInfo)GetMethodInfo().BindTypeParameters(type));
44                 }
45
46                 public sealed override MethodBase __GetMethodOnTypeDefinition()
47                 {
48                         return new ConstructorInfoImpl((MethodInfo)GetMethodInfo().__GetMethodOnTypeDefinition());
49                 }
50
51                 public sealed override MemberTypes MemberType
52                 {
53                         get { return MemberTypes.Constructor; }
54                 }
55
56                 public sealed override int __MethodRVA
57                 {
58                         get { return GetMethodInfo().__MethodRVA; }
59                 }
60
61                 public override bool ContainsGenericParameters
62                 {
63                         get { return GetMethodInfo().ContainsGenericParameters; }
64                 }
65
66                 public ParameterInfo __ReturnParameter
67                 {
68                         get { return new ParameterInfoWrapper(this, GetMethodInfo().ReturnParameter); }
69                 }
70
71                 public sealed override ParameterInfo[] GetParameters()
72                 {
73                         ParameterInfo[] parameters = GetMethodInfo().GetParameters();
74                         for (int i = 0; i < parameters.Length; i++)
75                         {
76                                 parameters[i] = new ParameterInfoWrapper(this, parameters[i]);
77                         }
78                         return parameters;
79                 }
80
81                 private sealed class ParameterInfoWrapper : ParameterInfo
82                 {
83                         private readonly ConstructorInfo ctor;
84                         private readonly ParameterInfo forward;
85
86                         internal ParameterInfoWrapper(ConstructorInfo ctor, ParameterInfo forward)
87                         {
88                                 this.ctor = ctor;
89                                 this.forward = forward;
90                         }
91
92                         public override string Name
93                         {
94                                 get { return forward.Name; }
95                         }
96
97                         public override Type ParameterType
98                         {
99                                 get { return forward.ParameterType; }
100                         }
101
102                         public override ParameterAttributes Attributes
103                         {
104                                 get { return forward.Attributes; }
105                         }
106
107                         public override int Position
108                         {
109                                 get { return forward.Position; }
110                         }
111
112                         public override object RawDefaultValue
113                         {
114                                 get { return forward.RawDefaultValue; }
115                         }
116
117                         public override CustomModifiers __GetCustomModifiers()
118                         {
119                                 return forward.__GetCustomModifiers();
120                         }
121
122                         public override MemberInfo Member
123                         {
124                                 get { return ctor; }
125                         }
126
127                         public override int MetadataToken
128                         {
129                                 get { return forward.MetadataToken; }
130                         }
131
132                         internal override Module Module
133                         {
134                                 get { return ctor.Module; }
135                         }
136
137                         internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
138                         {
139                                 return forward.GetCustomAttributesData(attributeType);
140                         }
141                 }
142         }
143
144         sealed class ConstructorInfoImpl : ConstructorInfo
145         {
146                 private readonly MethodInfo method;
147
148                 internal ConstructorInfoImpl(MethodInfo method)
149                 {
150                         this.method = method;
151                 }
152
153                 public override bool Equals(object obj)
154                 {
155                         ConstructorInfoImpl other = obj as ConstructorInfoImpl;
156                         return other != null && other.method.Equals(method);
157                 }
158
159                 public override int GetHashCode()
160                 {
161                         return method.GetHashCode();
162                 }
163
164                 public override MethodBody GetMethodBody()
165                 {
166                         return method.GetMethodBody();
167                 }
168
169                 public override CallingConventions CallingConvention
170                 {
171                         get { return method.CallingConvention; }
172                 }
173
174                 public override MethodAttributes Attributes
175                 {
176                         get { return method.Attributes; }
177                 }
178
179                 public override MethodImplAttributes GetMethodImplementationFlags()
180                 {
181                         return method.GetMethodImplementationFlags();
182                 }
183
184                 internal override int ParameterCount
185                 {
186                         get { return method.ParameterCount; }
187                 }
188
189                 public override Type DeclaringType
190                 {
191                         get { return method.DeclaringType; }
192                 }
193
194                 public override string Name
195                 {
196                         get { return method.Name; }
197                 }
198
199                 public override string ToString()
200                 {
201                         return method.ToString();
202                 }
203
204                 public override Module Module
205                 {
206                         get { return method.Module; }
207                 }
208
209                 public override int MetadataToken
210                 {
211                         get { return method.MetadataToken; }
212                 }
213
214                 public override bool __IsMissing
215                 {
216                         get { return method.__IsMissing; }
217                 }
218
219                 internal override MethodInfo GetMethodInfo()
220                 {
221                         return method;
222                 }
223
224                 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
225                 {
226                         return method.GetCustomAttributesData(attributeType);
227                 }
228
229                 internal override MethodInfo GetMethodOnTypeDefinition()
230                 {
231                         return method.GetMethodOnTypeDefinition();
232                 }
233
234                 internal override MethodSignature MethodSignature
235                 {
236                         get { return method.MethodSignature; }
237                 }
238
239                 internal override int ImportTo(Emit.ModuleBuilder module)
240                 {
241                         return method.ImportTo(module);
242                 }
243         }
244 }