private unsafe bool TryGetStaticRuntimeFieldHandleComponents(RuntimeFieldHandle runtimeFieldHandle, out RuntimeTypeHandle declaringTypeHandle, out string fieldName) { fieldName = null; declaringTypeHandle = default(RuntimeTypeHandle); // Make sure it's not a dynamically allocated RuntimeFieldHandle before we attempt to use it to parse native layout data Debug.Assert(((*(IntPtr *)&runtimeFieldHandle).ToInt64() & 0x1) == 0); RuntimeFieldHandleInfo *fieldData = *(RuntimeFieldHandleInfo **)&runtimeFieldHandle; IntPtr remainingSignature; if (!GetTypeFromSignatureAndContext(fieldData->NativeLayoutInfoSignature, null, null, out declaringTypeHandle, out remainingSignature)) { return(false); } // GetTypeFromSignatureAndContext parses the type from the signature and returns a pointer to the next // part of the native layout signature to read which we get the field name from var reader = GetNativeLayoutInfoReader(RuntimeAugments.GetModuleFromPointer(remainingSignature)); var parser = new NativeParser(reader, reader.AddressToOffset(remainingSignature)); fieldName = parser.GetString(); return(true); }
private unsafe bool TryGetStaticRuntimeFieldHandleComponents(RuntimeFieldHandle runtimeFieldHandle, out RuntimeTypeHandle declaringTypeHandle, out string fieldName) { fieldName = null; declaringTypeHandle = default(RuntimeTypeHandle); // Make sure it's not a dynamically allocated RuntimeFieldHandle before we attempt to use it to parse native layout data Debug.Assert(((*(IntPtr *)&runtimeFieldHandle).ToInt64() & 0x1) == 0); RuntimeFieldHandleInfo *fieldData = *(RuntimeFieldHandleInfo **)&runtimeFieldHandle; RuntimeSignature signature; #if !CORERT // If the system module is compiled with as a type manager, all modules are compiled as such if (ModuleList.Instance.SystemModule.Handle.IsTypeManager) #endif { // The native layout info signature is a pair. // The first is a pointer that points to the TypeManager indirection cell. // The second is the offset into the native layout info blob in that TypeManager, where the native signature is encoded. IntPtr *nativeLayoutInfoSignatureData = (IntPtr *)fieldData->NativeLayoutInfoSignature; signature = RuntimeSignature.CreateFromNativeLayoutSignature( new TypeManagerHandle(*(IntPtr *)nativeLayoutInfoSignatureData[0]), (uint)nativeLayoutInfoSignatureData[1].ToInt32()); } #if !CORERT else { IntPtr moduleHandle = RuntimeAugments.GetOSModuleFromPointer(fieldData->NativeLayoutInfoSignature); signature = RuntimeSignature.CreateFromNativeLayoutSignature( new TypeManagerHandle(moduleHandle), GetNativeLayoutInfoReader(new TypeManagerHandle(moduleHandle)).AddressToOffset(fieldData->NativeLayoutInfoSignature)); } #endif RuntimeSignature remainingSignature; if (!GetTypeFromSignatureAndContext(signature, null, null, out declaringTypeHandle, out remainingSignature)) { return(false); } // GetTypeFromSignatureAndContext parses the type from the signature and returns a pointer to the next // part of the native layout signature to read which we get the field name from var reader = GetNativeLayoutInfoReader(remainingSignature); var parser = new NativeParser(reader, remainingSignature.NativeLayoutOffset); fieldName = parser.GetString(); return(true); }