Пример #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"));
            }
        }
Пример #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"));
                }
            }
        }
Пример #3
0
        internal unsafe static void ConvertToNative(Type managedType, TypeNameNative *pNativeType)
        {
            if (!Environment.IsWinRTSupported)
            {
                throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_WinRT"));
            }
            string text2;

            if (managedType != null)
            {
                if (managedType.GetType() != typeof(RuntimeType))
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_WinRTSystemRuntimeType", new object[]
                    {
                        managedType.GetType().ToString()
                    }));
                }
                bool   flag;
                string text = WinRTTypeNameConverter.ConvertToWinRTTypeName(managedType, out flag);
                if (text != null)
                {
                    text2 = text;
                    if (flag)
                    {
                        pNativeType->typeKind = TypeKind.Primitive;
                    }
                    else
                    {
                        pNativeType->typeKind = TypeKind.Metadata;
                    }
                }
                else
                {
                    text2 = managedType.AssemblyQualifiedName;
                    pNativeType->typeKind = TypeKind.Projection;
                }
            }
            else
            {
                text2 = "";
                pNativeType->typeKind = TypeKind.Projection;
            }
            int errorCode = UnsafeNativeMethods.WindowsCreateString(text2, text2.Length, &pNativeType->typeName);

            Marshal.ThrowExceptionForHR(errorCode, new IntPtr(-1));
        }
Пример #4
0
        internal static unsafe void ConvertToNative(Type managedType, TypeNameNative *pNativeType)
        {
            if (!Environment.IsWinRTSupported)
            {
                throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_WinRT"));
            }
            string str;

            if (managedType != (Type)null)
            {
                if (managedType.GetType() != typeof(RuntimeType))
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_WinRTSystemRuntimeType", (object)managedType.GetType().ToString()));
                }
                bool   isPrimitive;
                string winRtTypeName = WinRTTypeNameConverter.ConvertToWinRTTypeName(managedType, out isPrimitive);
                if (winRtTypeName != null)
                {
                    str = winRtTypeName;
                    pNativeType->typeKind = !isPrimitive ? TypeKind.Metadata : TypeKind.Primitive;
                }
                else
                {
                    str = managedType.AssemblyQualifiedName;
                    pNativeType->typeKind = TypeKind.Projection;
                }
            }
            else
            {
                str = "";
                pNativeType->typeKind = TypeKind.Projection;
            }
            string sourceString = str;
            int    length       = sourceString.Length;
            IntPtr num          = (IntPtr) & pNativeType->typeName;

            Marshal.ThrowExceptionForHR(UnsafeNativeMethods.WindowsCreateString(sourceString, length, (IntPtr *)num), new IntPtr(-1));
        }