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