Babel.Compiler.CodeGeneratingVisitor.BoxIfNecessary C# (CSharp) Method

BoxIfNecessary() protected method

protected BoxIfNecessary ( Type sourceType, Type destinationType ) : void
sourceType System.Type
destinationType System.Type
return void
        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);
        }