Update mcs/class/Commons.Xml.Relaxng/Commons.Xml.Relaxng/RelaxngPattern.cs
[mono.git] / mcs / class / IKVM.Reflection / ConstructorInfo.cs
1 /*
2   Copyright (C) 2009-2012 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 using System.Diagnostics;
27
28 namespace IKVM.Reflection
29 {
30         public abstract class ConstructorInfo : MethodBase
31         {
32                 // prevent external subclasses
33                 internal ConstructorInfo()
34                 {
35                 }
36
37                 public static readonly string ConstructorName = ".ctor";
38                 public static readonly string TypeConstructorName = ".cctor";
39
40                 internal abstract MethodInfo GetMethodInfo();
41
42                 internal override MethodBase BindTypeParameters(Type type)
43                 {
44                         return new ConstructorInfoImpl((MethodInfo)GetMethodInfo().BindTypeParameters(type));
45                 }
46
47                 public sealed override MethodBase __GetMethodOnTypeDefinition()
48                 {
49                         return new ConstructorInfoImpl((MethodInfo)GetMethodInfo().__GetMethodOnTypeDefinition());
50                 }
51
52                 public sealed override MemberTypes MemberType
53                 {
54                         get { return MemberTypes.Constructor; }
55                 }
56
57                 public sealed override int __MethodRVA
58                 {
59                         get { return GetMethodInfo().__MethodRVA; }
60                 }
61
62                 public sealed override bool ContainsGenericParameters
63                 {
64                         get { return GetMethodInfo().ContainsGenericParameters; }
65                 }
66
67                 public ParameterInfo __ReturnParameter
68                 {
69                         get { return new ParameterInfoWrapper(this, GetMethodInfo().ReturnParameter); }
70                 }
71
72                 public sealed override ParameterInfo[] GetParameters()
73                 {
74                         ParameterInfo[] parameters = GetMethodInfo().GetParameters();
75                         for (int i = 0; i < parameters.Length; i++)
76                         {
77                                 parameters[i] = new ParameterInfoWrapper(this, parameters[i]);
78                         }
79                         return parameters;
80                 }
81
82                 internal sealed override MemberInfo SetReflectedType(Type type)
83                 {
84                         return new ConstructorInfoWithReflectedType(type, this);
85                 }
86         }
87
88         sealed class ConstructorInfoImpl : ConstructorInfo
89         {
90                 private readonly MethodInfo method;
91
92                 internal ConstructorInfoImpl(MethodInfo method)
93                 {
94                         this.method = method;
95                 }
96
97                 public override bool Equals(object obj)
98                 {
99                         ConstructorInfoImpl other = obj as ConstructorInfoImpl;
100                         return other != null && other.method.Equals(method);
101                 }
102
103                 public override int GetHashCode()
104                 {
105                         return method.GetHashCode();
106                 }
107
108                 public override MethodBody GetMethodBody()
109                 {
110                         return method.GetMethodBody();
111                 }
112
113                 public override CallingConventions CallingConvention
114                 {
115                         get { return method.CallingConvention; }
116                 }
117
118                 public override MethodAttributes Attributes
119                 {
120                         get { return method.Attributes; }
121                 }
122
123                 public override MethodImplAttributes GetMethodImplementationFlags()
124                 {
125                         return method.GetMethodImplementationFlags();
126                 }
127
128                 internal override int ParameterCount
129                 {
130                         get { return method.ParameterCount; }
131                 }
132
133                 public override Type DeclaringType
134                 {
135                         get { return method.DeclaringType; }
136                 }
137
138                 public override string Name
139                 {
140                         get { return method.Name; }
141                 }
142
143                 public override string ToString()
144                 {
145                         return method.ToString();
146                 }
147
148                 public override Module Module
149                 {
150                         get { return method.Module; }
151                 }
152
153                 public override int MetadataToken
154                 {
155                         get { return method.MetadataToken; }
156                 }
157
158                 public override bool __IsMissing
159                 {
160                         get { return method.__IsMissing; }
161                 }
162
163                 internal override MethodInfo GetMethodInfo()
164                 {
165                         return method;
166                 }
167
168                 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
169                 {
170                         return method.GetCustomAttributesData(attributeType);
171                 }
172
173                 internal override MethodInfo GetMethodOnTypeDefinition()
174                 {
175                         return method.GetMethodOnTypeDefinition();
176                 }
177
178                 internal override MethodSignature MethodSignature
179                 {
180                         get { return method.MethodSignature; }
181                 }
182
183                 internal override int ImportTo(Emit.ModuleBuilder module)
184                 {
185                         return method.ImportTo(module);
186                 }
187         }
188
189         sealed class ConstructorInfoWithReflectedType : ConstructorInfo
190         {
191                 private readonly Type reflectedType;
192                 private readonly ConstructorInfo ctor;
193
194                 internal ConstructorInfoWithReflectedType(Type reflectedType, ConstructorInfo ctor)
195                 {
196                         Debug.Assert(reflectedType != ctor.DeclaringType);
197                         this.reflectedType = reflectedType;
198                         this.ctor = ctor;
199                 }
200
201                 public override bool Equals(object obj)
202                 {
203                         ConstructorInfoWithReflectedType other = obj as ConstructorInfoWithReflectedType;
204                         return other != null
205                                 && other.reflectedType == reflectedType
206                                 && other.ctor == ctor;
207                 }
208
209                 public override int GetHashCode()
210                 {
211                         return reflectedType.GetHashCode() ^ ctor.GetHashCode();
212                 }
213
214                 public override MethodBody GetMethodBody()
215                 {
216                         return ctor.GetMethodBody();
217                 }
218
219                 public override CallingConventions CallingConvention
220                 {
221                         get { return ctor.CallingConvention; }
222                 }
223
224                 public override MethodAttributes Attributes
225                 {
226                         get { return ctor.Attributes; }
227                 }
228
229                 public override MethodImplAttributes GetMethodImplementationFlags()
230                 {
231                         return ctor.GetMethodImplementationFlags();
232                 }
233
234                 internal override int ParameterCount
235                 {
236                         get { return ctor.ParameterCount; }
237                 }
238
239                 public override Type DeclaringType
240                 {
241                         get { return ctor.DeclaringType; }
242                 }
243
244                 public override Type ReflectedType
245                 {
246                         get { return reflectedType; }
247                 }
248
249                 public override string Name
250                 {
251                         get { return ctor.Name; }
252                 }
253
254                 public override string ToString()
255                 {
256                         return ctor.ToString();
257                 }
258
259                 public override Module Module
260                 {
261                         get { return ctor.Module; }
262                 }
263
264                 public override int MetadataToken
265                 {
266                         get { return ctor.MetadataToken; }
267                 }
268
269                 public override bool __IsMissing
270                 {
271                         get { return ctor.__IsMissing; }
272                 }
273
274                 internal override MethodInfo GetMethodInfo()
275                 {
276                         return ctor.GetMethodInfo();
277                 }
278
279                 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
280                 {
281                         return ctor.GetCustomAttributesData(attributeType);
282                 }
283
284                 internal override MethodInfo GetMethodOnTypeDefinition()
285                 {
286                         return ctor.GetMethodOnTypeDefinition();
287                 }
288
289                 internal override MethodSignature MethodSignature
290                 {
291                         get { return ctor.MethodSignature; }
292                 }
293
294                 internal override int ImportTo(Emit.ModuleBuilder module)
295                 {
296                         return ctor.ImportTo(module);
297                 }
298         }
299 }