private ConstructorInfo GetMappedConstructorInfo(IType targetType, IConstructor source)
{
ConstructorInfo ci = GetConstructorInfo(source);
if (!ci.DeclaringType.IsGenericTypeDefinition)
{
// HACK: .NET Reflection doesn't allow calling
// TypeBuilder.GetConstructor(Type, ConstructorInfo) on types that aren't generic
// definitions, so we have to manually find the corresponding ConstructorInfo on the
// declaring type's definition before mapping it
Type definition = ci.DeclaringType.GetGenericTypeDefinition();
ci = Array.Find<ConstructorInfo>(
definition.GetConstructors(),
delegate(ConstructorInfo other) { return other.MetadataToken == ci.MetadataToken; });
}
return TypeBuilder.GetConstructor(GetSystemType(targetType), ci);
}