示例#1
0
        /// <summary>
        /// Creates a reference to a single-module assembly or a standalone module stored in memory.
        /// </summary>
        /// <param name="peImage">Assembly image.</param>
        /// <param name="properties">Reference properties (extern aliases, type embedding, <see cref="MetadataImageKind"/>).</param>
        /// <param name="documentation">Provides XML documentation for symbol found in the reference.</param>
        /// <param name="filePath">Optional path that describes the location of the metadata. The file doesn't need to exist on disk. The path is opaque to the compiler.</param>
        /// <remarks>
        /// Performance considerations:
        /// <para>
        /// It is recommended to use <see cref="AssemblyMetadata.CreateFromImage(IEnumerable{byte})"/> or <see cref="ModuleMetadata.CreateFromImage(IEnumerable{byte})"/>
        /// API when creating multiple references to the same metadata.
        /// Reusing <see cref="Metadata"/> object to create multiple references allows for sharing data across these references.
        /// </para>
        /// <para>
        /// The method makes a copy of the data and pins it. To avoid making a copy use an overload that takes an <see cref="ImmutableArray{T}"/>.
        /// The pinned memory is released when the resulting reference becomes unreachable and GC collects it. To control the lifetime of the pinned memory
        /// deterministically use <see cref="AssemblyMetadata.CreateFromStream(Stream, PEStreamOptions)"/>
        /// to create an <see cref="IDisposable"/> metadata object and
        /// <see cref="AssemblyMetadata.GetReference(DocumentationProvider, ImmutableArray{string}, bool, string, string)"/> to get a reference to it.
        /// </para>
        /// </remarks>
        /// <exception cref="ArgumentNullException"><paramref name="peImage"/> is null.</exception>
        public static PortableExecutableReference CreateFromImage(
            IEnumerable <byte> peImage,
            MetadataReferenceProperties properties = default,
            DocumentationProvider?documentation    = null,
            string?filePath = null)
        {
            var metadata = AssemblyMetadata.CreateFromImage(peImage);

            return(new MetadataImageReference(metadata, properties, documentation, filePath, display: null));
        }
 /// <summary>
 /// Creates a reference to a single-module assembly image.
 /// </summary>
 /// <param name="assemblyImage">Read-only assembly image.</param>
 /// <param name="documentation">Provides XML documentation for symbol found in the reference.</param>
 /// <param name="aliases">Reference aliases.</param>
 /// <param name="embedInteropTypes">True if interop types contained in the reference should be embedded to the compilation that uses the reference.</param>
 /// <param name="filePath">Optional path that describes the location of the metadata. The file doesn't need to exist on disk. The path is opaque to the compiler.</param>
 /// <param name="display">Display string for error reporting.</param>
 public MetadataImageReference(ImmutableArray <byte> assemblyImage, DocumentationProvider documentation = null, ImmutableArray <string> aliases = default(ImmutableArray <string>), bool embedInteropTypes = false, string filePath = null, string display = null)
     : this(AssemblyMetadata.CreateFromImage(RequireNonNull(assemblyImage, "assemblyImage")), documentation, aliases, embedInteropTypes, filePath, display)
 {
 }