protected virtual void BoxIfNecessary(Type sourceType,
Type destinationType)
{
Type adapterType =
typeManager.GetSupertypingAdapter(destinationType,
sourceType);
if (adapterType != null) {
ConstructorInfo[] constructors =
typeManager.GetConstructors(adapterType);
ilGenerator.Emit(OpCodes.Newobj, constructors[0]);
return;
}
if (sourceType.IsValueType &&
!destinationType.IsValueType)
ilGenerator.Emit(OpCodes.Box, sourceType);
if (destinationType.IsGenericParameter)
ilGenerator.Emit(OpCodes.Box, sourceType);
}