/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System; using dnlib.DotNet; namespace dnSpy.Contracts.AsmEditor.Compiler { /// /// Metadata reference /// public unsafe readonly struct CompilerMetadataReference { /// /// Raw bytes /// public void* Data { get; } /// /// Gets the size of /// public int Size { get; } /// /// Gets the assembly or null /// public IAssembly? Assembly { get; } /// /// Gets the filename or null if it doesn't exist on disk /// public string? Filename { get; } /// /// true if it's an assembly reference, false if it's a module reference /// public bool IsAssemblyReference { get; } CompilerMetadataReference(void* data, int size, IAssembly? assembly, string? filename, bool isAssemblyReference) { if (data is null) throw new ArgumentNullException(nameof(data)); if (size <= 0) throw new ArgumentOutOfRangeException(nameof(size)); Data = data; Size = size; Assembly = assembly; Filename = filename; IsAssemblyReference = isAssemblyReference; } /// /// Creates an assembly metadata reference /// /// File data /// Size of data /// Assembly owner or null /// Filename or null if it doesn't exist on disk /// public static CompilerMetadataReference CreateAssemblyReference(void* data, int size, IAssembly? assembly, string? filename = null) => new CompilerMetadataReference(data, size, assembly, filename, true); /// /// Creates a module metadata reference /// /// File data /// Size of data /// Assembly owner or null /// Filename or null if it doesn't exist on disk /// public static CompilerMetadataReference CreateModuleReference(void* data, int size, IAssembly? assembly, string? filename = null) => new CompilerMetadataReference(data, size, assembly, filename, false); } }