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"));
                }
            }
        }
Ejemplo n.º 3
0
        internal static unsafe void GetType(object target, TypeNameNative *pIndexedParamType)
        {
            if (target is IGetProxyTarget proxy)
            {
                target = proxy.GetTarget();
            }

            SystemTypeMarshaler.ConvertToNative(target.GetType(), pIndexedParamType);
        }
 internal unsafe static void ConvertContentsToNative_Type(ref Type[] managedArray, IntPtr pNativeHome)
 {
     if (managedArray != null)
     {
         TypeNameNative *ptr = *(IntPtr *)((void *)pNativeHome);
         for (int i = 0; i < managedArray.Length; i++)
         {
             SystemTypeMarshaler.ConvertToNative(managedArray[i], ptr + i);
         }
     }
 }
Ejemplo n.º 5
0
        static internal unsafe void GetType(object target, TypeNameNative *pIndexedParamType)
        {
            IGetProxyTarget proxy = target as IGetProxyTarget;

            if (proxy != null)
            {
                target = proxy.GetTarget();
            }

            SystemTypeMarshaler.ConvertToNative(target.GetType(), pIndexedParamType);
        }
        internal unsafe static void ClearNativeContents_Type(IntPtr pNativeHome, int cElements)
        {
            TypeNameNative *ptr = *(IntPtr *)((void *)pNativeHome);

            if (ptr != null)
            {
                for (int i = 0; i < cElements; i++)
                {
                    SystemTypeMarshaler.ClearNative(ptr);
                    ptr++;
                }
            }
        }
Ejemplo n.º 7
0
        internal static unsafe void ConvertContentsToNative_Type(ref Type[] managedArray, IntPtr pNativeHome)
        {
            if (managedArray == null)
            {
                return;
            }
            TypeNameNative *typeNameNativePtr = (TypeNameNative *)*(IntPtr *)(void *)pNativeHome;

            for (int index = 0; index < managedArray.Length; ++index)
            {
                SystemTypeMarshaler.ConvertToNative(managedArray[index], typeNameNativePtr + index);
            }
        }
Ejemplo n.º 8
0
        internal static unsafe void ClearNativeContents_Type(IntPtr pNativeHome, int cElements)
        {
            TypeNameNative *pNativeType = (TypeNameNative *)*(IntPtr *)(void *)pNativeHome;

            if ((IntPtr)pNativeType == IntPtr.Zero)
            {
                return;
            }
            for (int index = 0; index < cElements; ++index)
            {
                SystemTypeMarshaler.ClearNative(pNativeType);
                ++pNativeType;
            }
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
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));
        }
Ejemplo n.º 11
0
        //
        // Creates a ICustomProperty implementation for Jupiter
        // Called from ICustomPropertyProvider_GetIndexedProperty from within runtime
        //
        internal static unsafe ICustomProperty?CreateIndexedProperty(object target, string propertyName, TypeNameNative *pIndexedParamType)
        {
            Debug.Assert(target != null);
            Debug.Assert(propertyName != null);

            Type?indexedParamType = null;

            SystemTypeMarshaler.ConvertToManaged(pIndexedParamType, ref indexedParamType);

            return(CreateIndexedProperty(target, propertyName, indexedParamType !));
        }
Ejemplo n.º 12
0
        internal unsafe static void ClearNative(TypeNameNative *pNativeType)
        {
            TypeNameNative typeNameNative = *pNativeType;

            UnsafeNativeMethods.WindowsDeleteString(pNativeType->typeName);
        }
Ejemplo n.º 13
0
        static internal unsafe ICustomProperty CreateIndexedProperty(object target, string propertyName, TypeNameNative *pIndexedParamType)
        {
            Contract.Requires(target != null);
            Contract.Requires(propertyName != null);

            Type indexedParamType = null;

            SystemTypeMarshaler.ConvertToManaged(pIndexedParamType, ref indexedParamType);

            return(CreateIndexedProperty(target, propertyName, indexedParamType));
        }
Ejemplo n.º 14
0
 static internal unsafe void GetType(object target, TypeNameNative *pIndexedParamType)
 {
     SystemTypeMarshaler.ConvertToNative(target.GetType(), pIndexedParamType);
 }
Ejemplo n.º 15
0
        internal unsafe static ICustomProperty CreateIndexedProperty(object target, string propertyName, TypeNameNative *pIndexedParamType)
        {
            Type indexedParamType = null;

            SystemTypeMarshaler.ConvertToManaged(pIndexedParamType, ref indexedParamType);
            return(ICustomPropertyProviderImpl.CreateIndexedProperty(target, propertyName, indexedParamType));
        }