Exemplo n.º 1
0
        internal static bool TryGetBoxingWrapperType(RuntimeTypeHandle typeHandle, object target, out RuntimeTypeHandle boxingWrapperType, out int boxingPropertyType, out IntPtr boxingStub)
        {
            int moduleIndex, typeIndex;

            if (GetIndicesForBoxing(typeHandle, out moduleIndex, out typeIndex))
            {
                McgBoxingData boxingData = s_modules[moduleIndex].GetBoxingDataByIndex(typeIndex);
                boxingWrapperType  = boxingData.CLRBoxingWrapperType;
                boxingPropertyType = boxingData.PropertyType;
                boxingStub         = boxingData.BoxingStub;
                return(true);
            }

            if (target is Type)
            {
                if (GetIndicesForBoxing(typeof(System.Type).TypeHandle, out moduleIndex, out typeIndex))
                {
                    McgBoxingData boxingData = s_modules[moduleIndex].GetBoxingDataByIndex(typeIndex);
                    boxingWrapperType  = boxingData.CLRBoxingWrapperType;
                    boxingPropertyType = boxingData.PropertyType;
                    boxingStub         = boxingData.BoxingStub;
                    return(true);
                }
            }

            boxingWrapperType  = default(RuntimeTypeHandle);
            boxingPropertyType = default(int);
            boxingStub         = default(IntPtr);
            return(false);
        }
        internal static bool TryGetBoxingWrapperType(RuntimeTypeHandle typeHandle, object target, out RuntimeTypeHandle boxingWrapperType, out int boxingPropertyType, out IntPtr boxingStub)
        {
            int moduleIndex, typeIndex;

            if (GetIndicesForBoxing(typeHandle, out moduleIndex, out typeIndex))
            {
                McgBoxingData boxingData = s_modules[moduleIndex].GetBoxingDataByIndex(typeIndex);
                boxingWrapperType  = boxingData.CLRBoxingWrapperType;
                boxingPropertyType = boxingData.PropertyType;
                boxingStub         = boxingData.BoxingStub;
                return(true);
            }

            if (target is Type)
            {
                if (GetIndicesForBoxing(typeof(System.Type).TypeHandle, out moduleIndex, out typeIndex))
                {
                    McgBoxingData boxingData = s_modules[moduleIndex].GetBoxingDataByIndex(typeIndex);
                    boxingWrapperType  = boxingData.CLRBoxingWrapperType;
                    boxingPropertyType = boxingData.PropertyType;
                    boxingStub         = boxingData.BoxingStub;
                    return(true);
                }
            }

#if !RHTESTCL && PROJECTN && ENABLE_WINRT
            // Dynamic boxing support
            // TODO: Consider to use the field boxingStub for all projected reference types.
            // TODO: now it is only used for boxing "System.Uri".
            // TODO: For Projected value types, IReference<T>.get_Value(out T) should marshal it correctly.
            // TODO: For projected refernce types, IReference<Ojbect> won't do correct marshal for you.
            boxingStub = default(IntPtr);
            if (McgModuleManager.UseDynamicInterop && DynamicInteropBoxingHelpers.Boxing(typeHandle, out boxingWrapperType, out boxingPropertyType))
            {
                return(true);
            }
#endif

            boxingWrapperType  = default(RuntimeTypeHandle);
            boxingPropertyType = default(int);
            boxingStub         = default(IntPtr);
            return(false);
        }