2 Copyright (C) 2009-2012 Jeroen Frijters
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.
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:
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.
25 using System.Collections.Generic;
26 using System.Diagnostics;
28 namespace IKVM.Reflection
30 public abstract class ConstructorInfo : MethodBase
32 // prevent external subclasses
33 internal ConstructorInfo()
37 public static readonly string ConstructorName = ".ctor";
38 public static readonly string TypeConstructorName = ".cctor";
40 internal abstract MethodInfo GetMethodInfo();
42 internal override MethodBase BindTypeParameters(Type type)
44 return new ConstructorInfoImpl((MethodInfo)GetMethodInfo().BindTypeParameters(type));
47 public sealed override MethodBase __GetMethodOnTypeDefinition()
49 return new ConstructorInfoImpl((MethodInfo)GetMethodInfo().__GetMethodOnTypeDefinition());
52 public sealed override MemberTypes MemberType
54 get { return MemberTypes.Constructor; }
57 public sealed override int __MethodRVA
59 get { return GetMethodInfo().__MethodRVA; }
62 public sealed override bool ContainsGenericParameters
64 get { return GetMethodInfo().ContainsGenericParameters; }
67 public ParameterInfo __ReturnParameter
69 get { return new ParameterInfoWrapper(this, GetMethodInfo().ReturnParameter); }
72 public sealed override ParameterInfo[] GetParameters()
74 ParameterInfo[] parameters = GetMethodInfo().GetParameters();
75 for (int i = 0; i < parameters.Length; i++)
77 parameters[i] = new ParameterInfoWrapper(this, parameters[i]);
82 internal sealed override MemberInfo SetReflectedType(Type type)
84 return new ConstructorInfoWithReflectedType(type, this);
88 sealed class ConstructorInfoImpl : ConstructorInfo
90 private readonly MethodInfo method;
92 internal ConstructorInfoImpl(MethodInfo method)
97 public override bool Equals(object obj)
99 ConstructorInfoImpl other = obj as ConstructorInfoImpl;
100 return other != null && other.method.Equals(method);
103 public override int GetHashCode()
105 return method.GetHashCode();
108 public override MethodBody GetMethodBody()
110 return method.GetMethodBody();
113 public override CallingConventions CallingConvention
115 get { return method.CallingConvention; }
118 public override MethodAttributes Attributes
120 get { return method.Attributes; }
123 public override MethodImplAttributes GetMethodImplementationFlags()
125 return method.GetMethodImplementationFlags();
128 internal override int ParameterCount
130 get { return method.ParameterCount; }
133 public override Type DeclaringType
135 get { return method.DeclaringType; }
138 public override string Name
140 get { return method.Name; }
143 public override string ToString()
145 return method.ToString();
148 public override Module Module
150 get { return method.Module; }
153 public override int MetadataToken
155 get { return method.MetadataToken; }
158 public override bool __IsMissing
160 get { return method.__IsMissing; }
163 internal override MethodInfo GetMethodInfo()
168 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
170 return method.GetCustomAttributesData(attributeType);
173 internal override MethodInfo GetMethodOnTypeDefinition()
175 return method.GetMethodOnTypeDefinition();
178 internal override MethodSignature MethodSignature
180 get { return method.MethodSignature; }
183 internal override int ImportTo(Emit.ModuleBuilder module)
185 return method.ImportTo(module);
189 sealed class ConstructorInfoWithReflectedType : ConstructorInfo
191 private readonly Type reflectedType;
192 private readonly ConstructorInfo ctor;
194 internal ConstructorInfoWithReflectedType(Type reflectedType, ConstructorInfo ctor)
196 Debug.Assert(reflectedType != ctor.DeclaringType);
197 this.reflectedType = reflectedType;
201 public override bool Equals(object obj)
203 ConstructorInfoWithReflectedType other = obj as ConstructorInfoWithReflectedType;
205 && other.reflectedType == reflectedType
206 && other.ctor == ctor;
209 public override int GetHashCode()
211 return reflectedType.GetHashCode() ^ ctor.GetHashCode();
214 public override MethodBody GetMethodBody()
216 return ctor.GetMethodBody();
219 public override CallingConventions CallingConvention
221 get { return ctor.CallingConvention; }
224 public override MethodAttributes Attributes
226 get { return ctor.Attributes; }
229 public override MethodImplAttributes GetMethodImplementationFlags()
231 return ctor.GetMethodImplementationFlags();
234 internal override int ParameterCount
236 get { return ctor.ParameterCount; }
239 public override Type DeclaringType
241 get { return ctor.DeclaringType; }
244 public override Type ReflectedType
246 get { return reflectedType; }
249 public override string Name
251 get { return ctor.Name; }
254 public override string ToString()
256 return ctor.ToString();
259 public override Module Module
261 get { return ctor.Module; }
264 public override int MetadataToken
266 get { return ctor.MetadataToken; }
269 public override bool __IsMissing
271 get { return ctor.__IsMissing; }
274 internal override MethodInfo GetMethodInfo()
276 return ctor.GetMethodInfo();
279 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
281 return ctor.GetCustomAttributesData(attributeType);
284 internal override MethodInfo GetMethodOnTypeDefinition()
286 return ctor.GetMethodOnTypeDefinition();
289 internal override MethodSignature MethodSignature
291 get { return ctor.MethodSignature; }
294 internal override int ImportTo(Emit.ModuleBuilder module)
296 return ctor.ImportTo(module);