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 MemberTypes MemberType
48 get { return MemberTypes.Constructor; }
51 public override bool ContainsGenericParameters
53 get { return GetMethodInfo().ContainsGenericParameters; }
56 public sealed override ParameterInfo[] GetParameters()
58 ParameterInfo[] parameters = GetMethodInfo().GetParameters();
59 for (int i = 0; i < parameters.Length; i++)
61 parameters[i] = new ParameterInfoWrapper(this, parameters[i]);
66 private sealed class ParameterInfoWrapper : ParameterInfo
68 private readonly ConstructorInfo ctor;
69 private readonly ParameterInfo forward;
71 internal ParameterInfoWrapper(ConstructorInfo ctor, ParameterInfo forward)
74 this.forward = forward;
77 public override string Name
79 get { return forward.Name; }
82 public override Type ParameterType
84 get { return forward.ParameterType; }
87 public override ParameterAttributes Attributes
89 get { return forward.Attributes; }
92 public override int Position
94 get { return forward.Position; }
97 public override object RawDefaultValue
99 get { return forward.RawDefaultValue; }
102 public override Type[] GetOptionalCustomModifiers()
104 return forward.GetOptionalCustomModifiers();
107 public override Type[] GetRequiredCustomModifiers()
109 return forward.GetRequiredCustomModifiers();
112 public override MemberInfo Member
117 public override int MetadataToken
119 get { return forward.MetadataToken; }
122 internal override Module Module
124 get { return ctor.Module; }
127 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
129 return forward.GetCustomAttributesData(attributeType);
134 sealed class ConstructorInfoImpl : ConstructorInfo
136 private readonly MethodInfo method;
138 internal ConstructorInfoImpl(MethodInfo method)
140 this.method = method;
143 public override bool Equals(object obj)
145 ConstructorInfoImpl other = obj as ConstructorInfoImpl;
146 return other != null && other.method.Equals(method);
149 public override int GetHashCode()
151 return method.GetHashCode();
154 public override MethodBody GetMethodBody()
156 return method.GetMethodBody();
159 public override CallingConventions CallingConvention
161 get { return method.CallingConvention; }
164 public override MethodAttributes Attributes
166 get { return method.Attributes; }
169 public override MethodImplAttributes GetMethodImplementationFlags()
171 return method.GetMethodImplementationFlags();
174 internal override int ParameterCount
176 get { return method.ParameterCount; }
179 public override Type DeclaringType
181 get { return method.DeclaringType; }
184 public override string Name
186 get { return method.Name; }
189 public override string ToString()
191 return method.ToString();
194 public override Module Module
196 get { return method.Module; }
199 public override int MetadataToken
201 get { return method.MetadataToken; }
204 public override bool __IsMissing
206 get { return method.__IsMissing; }
209 internal override MethodInfo GetMethodInfo()
214 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
216 return method.GetCustomAttributesData(attributeType);
219 internal override MethodInfo GetMethodOnTypeDefinition()
221 return method.GetMethodOnTypeDefinition();
224 internal override MethodSignature MethodSignature
226 get { return method.MethodSignature; }
229 internal override int ImportTo(Emit.ModuleBuilder module)
231 return method.ImportTo(module);