Ejemplo n.º 1
0
        internal unsafe static void ConvertToManaged(TypeNameNative *pNativeType, ref Type managedType)
        {
            if (!Environment.IsWinRTSupported)
            {
                throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_WinRT"));
            }
            string text = WindowsRuntimeMarshal.HStringToString(pNativeType->typeName);

            if (string.IsNullOrEmpty(text))
            {
                managedType = null;
                return;
            }
            if (pNativeType->typeKind == TypeKind.Projection)
            {
                managedType = Type.GetType(text, true);
                return;
            }
            bool flag;

            managedType = WinRTTypeNameConverter.GetTypeFromWinRTTypeName(text, out flag);
            if (flag != (pNativeType->typeKind == TypeKind.Primitive))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_Unexpected_TypeSource"));
            }
        }
Ejemplo n.º 2
0
        internal static unsafe void ConvertToManaged(TypeNameNative *pNativeType, ref Type managedType)
        {
            if (!Environment.IsWinRTSupported)
            {
                throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_WinRT"));
            }
            string @string = WindowsRuntimeMarshal.HStringToString(pNativeType->typeName);

            if (string.IsNullOrEmpty(@string))
            {
                managedType = (Type)null;
            }
            else if (pNativeType->typeKind == TypeKind.Projection)
            {
                managedType = Type.GetType(@string, true);
            }
            else
            {
                bool isPrimitive;
                managedType = WinRTTypeNameConverter.GetTypeFromWinRTTypeName(@string, out isPrimitive);
                if (isPrimitive != (pNativeType->typeKind == TypeKind.Primitive))
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_Unexpected_TypeSource"));
                }
            }
        }