2 Copyright (C) 2009 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;
27 namespace IKVM.Reflection
29 public abstract class ConstructorInfo : MethodBase
31 // prevent external subclasses
32 internal ConstructorInfo()
36 public static readonly string ConstructorName = ".ctor";
37 public static readonly string TypeConstructorName = ".cctor";
39 internal abstract MethodInfo GetMethodInfo();
41 internal override MethodBase BindTypeParameters(Type type)
43 return new ConstructorInfoImpl((MethodInfo)GetMethodInfo().BindTypeParameters(type));
46 public sealed override MethodBase __GetMethodOnTypeDefinition()
48 return new ConstructorInfoImpl((MethodInfo)GetMethodInfo().__GetMethodOnTypeDefinition());
51 public sealed override MemberTypes MemberType
53 get { return MemberTypes.Constructor; }
56 public sealed override int __MethodRVA
58 get { return GetMethodInfo().__MethodRVA; }
61 public override bool ContainsGenericParameters
63 get { return GetMethodInfo().ContainsGenericParameters; }
66 public ParameterInfo __ReturnParameter
68 get { return new ParameterInfoWrapper(this, GetMethodInfo().ReturnParameter); }
71 public sealed override ParameterInfo[] GetParameters()
73 ParameterInfo[] parameters = GetMethodInfo().GetParameters();
74 for (int i = 0; i < parameters.Length; i++)
76 parameters[i] = new ParameterInfoWrapper(this, parameters[i]);
81 private sealed class ParameterInfoWrapper : ParameterInfo
83 private readonly ConstructorInfo ctor;
84 private readonly ParameterInfo forward;
86 internal ParameterInfoWrapper(ConstructorInfo ctor, ParameterInfo forward)
89 this.forward = forward;
92 public override string Name
94 get { return forward.Name; }
97 public override Type ParameterType
99 get { return forward.ParameterType; }
102 public override ParameterAttributes Attributes
104 get { return forward.Attributes; }
107 public override int Position
109 get { return forward.Position; }
112 public override object RawDefaultValue
114 get { return forward.RawDefaultValue; }
117 public override CustomModifiers __GetCustomModifiers()
119 return forward.__GetCustomModifiers();
122 public override MemberInfo Member
127 public override int MetadataToken
129 get { return forward.MetadataToken; }
132 internal override Module Module
134 get { return ctor.Module; }
137 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
139 return forward.GetCustomAttributesData(attributeType);
144 sealed class ConstructorInfoImpl : ConstructorInfo
146 private readonly MethodInfo method;
148 internal ConstructorInfoImpl(MethodInfo method)
150 this.method = method;
153 public override bool Equals(object obj)
155 ConstructorInfoImpl other = obj as ConstructorInfoImpl;
156 return other != null && other.method.Equals(method);
159 public override int GetHashCode()
161 return method.GetHashCode();
164 public override MethodBody GetMethodBody()
166 return method.GetMethodBody();
169 public override CallingConventions CallingConvention
171 get { return method.CallingConvention; }
174 public override MethodAttributes Attributes
176 get { return method.Attributes; }
179 public override MethodImplAttributes GetMethodImplementationFlags()
181 return method.GetMethodImplementationFlags();
184 internal override int ParameterCount
186 get { return method.ParameterCount; }
189 public override Type DeclaringType
191 get { return method.DeclaringType; }
194 public override string Name
196 get { return method.Name; }
199 public override string ToString()
201 return method.ToString();
204 public override Module Module
206 get { return method.Module; }
209 public override int MetadataToken
211 get { return method.MetadataToken; }
214 public override bool __IsMissing
216 get { return method.__IsMissing; }
219 internal override MethodInfo GetMethodInfo()
224 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
226 return method.GetCustomAttributesData(attributeType);
229 internal override MethodInfo GetMethodOnTypeDefinition()
231 return method.GetMethodOnTypeDefinition();
234 internal override MethodSignature MethodSignature
236 get { return method.MethodSignature; }
239 internal override int ImportTo(Emit.ModuleBuilder module)
241 return method.ImportTo(module);