internal static unsafe IntPtr GetTypeHelper(IntPtr th, IntPtr pGenericArgs, int cGenericArgs, IntPtr pModifiers, int cModifiers) { Type runtimeType = new RuntimeTypeHandle(th.ToPointer()).GetRuntimeType(); if (runtimeType == null) { return(th); } if (cGenericArgs > 0) { Type[] typeArguments = new Type[cGenericArgs]; void **voidPtr = (void **)pGenericArgs.ToPointer(); for (int i = 0; i < typeArguments.Length; i++) { RuntimeTypeHandle handle = new RuntimeTypeHandle((void *)Marshal.ReadIntPtr((IntPtr)voidPtr, i * sizeof(void *))); typeArguments[i] = Type.GetTypeFromHandle(handle); if (typeArguments[i] == null) { return(IntPtr.Zero); } } runtimeType = runtimeType.MakeGenericType(typeArguments); } if (cModifiers > 0) { int *numPtr = (int *)pModifiers.ToPointer(); for (int j = 0; j < cModifiers; j++) { if (((byte)Marshal.ReadInt32((IntPtr)numPtr, j * 4)) == 15) { runtimeType = runtimeType.MakePointerType(); } else if (((byte)Marshal.ReadInt32((IntPtr)numPtr, j * 4)) == 0x10) { runtimeType = runtimeType.MakeByRefType(); } else if (((byte)Marshal.ReadInt32((IntPtr)numPtr, j * 4)) == 0x1d) { runtimeType = runtimeType.MakeArrayType(); } else { runtimeType = runtimeType.MakeArrayType(Marshal.ReadInt32((IntPtr)numPtr, ++j * 4)); } } } return(runtimeType.GetTypeHandleInternal().Value); }
internal static unsafe IntPtr GetTypeHelper(IntPtr th, IntPtr pGenericArgs, int cGenericArgs, IntPtr pModifiers, int cModifiers) { Type runtimeType = new RuntimeTypeHandle(th.ToPointer()).GetRuntimeType(); if (runtimeType == null) { return th; } if (cGenericArgs > 0) { Type[] typeArguments = new Type[cGenericArgs]; void** voidPtr = (void**) pGenericArgs.ToPointer(); for (int i = 0; i < typeArguments.Length; i++) { RuntimeTypeHandle handle = new RuntimeTypeHandle((void*) Marshal.ReadIntPtr((IntPtr) voidPtr, i * sizeof(void*))); typeArguments[i] = Type.GetTypeFromHandle(handle); if (typeArguments[i] == null) { return IntPtr.Zero; } } runtimeType = runtimeType.MakeGenericType(typeArguments); } if (cModifiers > 0) { int* numPtr = (int*) pModifiers.ToPointer(); for (int j = 0; j < cModifiers; j++) { if (((byte) Marshal.ReadInt32((IntPtr) numPtr, j * 4)) == 15) { runtimeType = runtimeType.MakePointerType(); } else if (((byte) Marshal.ReadInt32((IntPtr) numPtr, j * 4)) == 0x10) { runtimeType = runtimeType.MakeByRefType(); } else if (((byte) Marshal.ReadInt32((IntPtr) numPtr, j * 4)) == 0x1d) { runtimeType = runtimeType.MakeArrayType(); } else { runtimeType = runtimeType.MakeArrayType(Marshal.ReadInt32((IntPtr) numPtr, ++j * 4)); } } } return runtimeType.GetTypeHandleInternal().Value; }