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