Merge pull request #200 from ch5oh/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 override bool ContainsGenericParameters
57                 {
58                         get { return GetMethodInfo().ContainsGenericParameters; }
59                 }
60
61                 public ParameterInfo __ReturnParameter
62                 {
63                         get { return new ParameterInfoWrapper(this, GetMethodInfo().ReturnParameter); }
64                 }
65
66                 public sealed override ParameterInfo[] GetParameters()
67                 {
68                         ParameterInfo[] parameters = GetMethodInfo().GetParameters();
69                         for (int i = 0; i < parameters.Length; i++)
70                         {
71                                 parameters[i] = new ParameterInfoWrapper(this, parameters[i]);
72                         }
73                         return parameters;
74                 }
75
76                 private sealed class ParameterInfoWrapper : ParameterInfo
77                 {
78                         private readonly ConstructorInfo ctor;
79                         private readonly ParameterInfo forward;
80
81                         internal ParameterInfoWrapper(ConstructorInfo ctor, ParameterInfo forward)
82                         {
83                                 this.ctor = ctor;
84                                 this.forward = forward;
85                         }
86
87                         public override string Name
88                         {
89                                 get { return forward.Name; }
90                         }
91
92                         public override Type ParameterType
93                         {
94                                 get { return forward.ParameterType; }
95                         }
96
97                         public override ParameterAttributes Attributes
98                         {
99                                 get { return forward.Attributes; }
100                         }
101
102                         public override int Position
103                         {
104                                 get { return forward.Position; }
105                         }
106
107                         public override object RawDefaultValue
108                         {
109                                 get { return forward.RawDefaultValue; }
110                         }
111
112                         public override CustomModifiers __GetCustomModifiers()
113                         {
114                                 return forward.__GetCustomModifiers();
115                         }
116
117                         public override MemberInfo Member
118                         {
119                                 get { return ctor; }
120                         }
121
122                         public override int MetadataToken
123                         {
124                                 get { return forward.MetadataToken; }
125                         }
126
127                         internal override Module Module
128                         {
129                                 get { return ctor.Module; }
130                         }
131
132                         internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
133                         {
134                                 return forward.GetCustomAttributesData(attributeType);
135                         }
136                 }
137         }
138
139         sealed class ConstructorInfoImpl : ConstructorInfo
140         {
141                 private readonly MethodInfo method;
142
143                 internal ConstructorInfoImpl(MethodInfo method)
144                 {
145                         this.method = method;
146                 }
147
148                 public override bool Equals(object obj)
149                 {
150                         ConstructorInfoImpl other = obj as ConstructorInfoImpl;
151                         return other != null && other.method.Equals(method);
152                 }
153
154                 public override int GetHashCode()
155                 {
156                         return method.GetHashCode();
157                 }
158
159                 public override MethodBody GetMethodBody()
160                 {
161                         return method.GetMethodBody();
162                 }
163
164                 public override CallingConventions CallingConvention
165                 {
166                         get { return method.CallingConvention; }
167                 }
168
169                 public override MethodAttributes Attributes
170                 {
171                         get { return method.Attributes; }
172                 }
173
174                 public override MethodImplAttributes GetMethodImplementationFlags()
175                 {
176                         return method.GetMethodImplementationFlags();
177                 }
178
179                 internal override int ParameterCount
180                 {
181                         get { return method.ParameterCount; }
182                 }
183
184                 public override Type DeclaringType
185                 {
186                         get { return method.DeclaringType; }
187                 }
188
189                 public override string Name
190                 {
191                         get { return method.Name; }
192                 }
193
194                 public override string ToString()
195                 {
196                         return method.ToString();
197                 }
198
199                 public override Module Module
200                 {
201                         get { return method.Module; }
202                 }
203
204                 public override int MetadataToken
205                 {
206                         get { return method.MetadataToken; }
207                 }
208
209                 public override bool __IsMissing
210                 {
211                         get { return method.__IsMissing; }
212                 }
213
214                 internal override MethodInfo GetMethodInfo()
215                 {
216                         return method;
217                 }
218
219                 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
220                 {
221                         return method.GetCustomAttributesData(attributeType);
222                 }
223
224                 internal override MethodInfo GetMethodOnTypeDefinition()
225                 {
226                         return method.GetMethodOnTypeDefinition();
227                 }
228
229                 internal override MethodSignature MethodSignature
230                 {
231                         get { return method.MethodSignature; }
232                 }
233
234                 internal override int ImportTo(Emit.ModuleBuilder module)
235                 {
236                         return method.ImportTo(module);
237                 }
238         }
239 }