private static unsafe bool TryGetMetadataBlock(IntPtr ptr, uint size, out MetadataBlock block) { try { var reader = new MetadataReader((byte *)ptr, (int)size); var moduleDef = reader.GetModuleDefinition(); var moduleVersionId = reader.GetGuid(moduleDef.Mvid); var generationId = reader.GetGuid(moduleDef.GenerationId); block = new MetadataBlock(moduleVersionId, generationId, ptr, (int)size); return(true); } catch (BadImageFormatException) { block = default; return(false); } }
private static bool TryGetMetadataBlock(ImmutableArray <MetadataBlock> previousMetadataBlocks, int index, IntPtr ptr, uint size, out MetadataBlock block) { if (!previousMetadataBlocks.IsDefault && index < previousMetadataBlocks.Length) { var previousBlock = previousMetadataBlocks[index]; if (previousBlock.Pointer == ptr && previousBlock.Size == size) { block = previousBlock; return(true); } } return(TryGetMetadataBlock(ptr, size, out block)); }