/// <summary> /// Adds a module to an existing assembly /// </summary> /// <param name="assembly">Assembly</param> /// <param name="moduleBytes">Raw PE file bytes</param> /// <param name="isFileLayout">true if file layout, false if memory layout</param> /// <param name="isInMemory">true if the module is in memory (<see cref="DmdModule.IsInMemory"/>)</param> /// <param name="isDynamic">true if it's a dynamic module (types can be added at runtime) (<see cref="DmdModule.IsDynamic"/>)</param> /// <param name="fullyQualifiedName">The fully qualified name of the module (<see cref="DmdModule.FullyQualifiedName"/>). See <see cref="DmdModule.GetFullyQualifiedName(bool, bool, string)"/></param> /// <returns></returns> public DmdModule CreateModule(DmdAssembly assembly, byte[] moduleBytes, bool isFileLayout, bool isInMemory, bool isDynamic, string fullyQualifiedName) { if (moduleBytes == null) { throw new ArgumentNullException(nameof(moduleBytes)); } return(CreateModule(assembly, () => new DmdLazyMetadataBytesArray(moduleBytes, isFileLayout), isInMemory, isDynamic, fullyQualifiedName)); }
/// <summary> /// Adds a module to an existing assembly /// </summary> /// <param name="assembly">Assembly</param> /// <param name="filename">Filename</param> /// <param name="isFileLayout">true if file layout, false if memory layout</param> /// <param name="isInMemory">true if the module is in memory (<see cref="DmdModule.IsInMemory"/>)</param> /// <param name="isDynamic">true if it's a dynamic module (types can be added at runtime) (<see cref="DmdModule.IsDynamic"/>)</param> /// <param name="fullyQualifiedName">The fully qualified name of the module (<see cref="DmdModule.FullyQualifiedName"/>). See <see cref="DmdModule.GetFullyQualifiedName(bool, bool, string)"/></param> /// <returns></returns> public DmdModule CreateModule(DmdAssembly assembly, string filename, bool isFileLayout = true, bool isInMemory = false, bool isDynamic = false, string fullyQualifiedName = null) { if (filename == null) { throw new ArgumentNullException(nameof(filename)); } return(CreateModule(assembly, () => new DmdLazyMetadataBytesFile(filename, isFileLayout), isInMemory, isDynamic, fullyQualifiedName ?? filename)); }
/// <summary> /// Adds a module to an existing assembly /// </summary> /// <param name="assembly">Assembly</param> /// <param name="comMetadata">COM <c>IMetaDataImport</c> instance</param> /// <param name="dynamicModuleHelper">Helper class</param> /// <param name="dispatcher">Dispatcher to use when accessing <paramref name="comMetadata"/></param> /// <param name="isInMemory">true if the module is in memory (<see cref="DmdModule.IsInMemory"/>)</param> /// <param name="isDynamic">true if it's a dynamic module (types can be added at runtime) (<see cref="DmdModule.IsDynamic"/>)</param> /// <param name="fullyQualifiedName">The fully qualified name of the module (<see cref="DmdModule.FullyQualifiedName"/>). See <see cref="DmdModule.GetFullyQualifiedName(bool, bool, string)"/></param> /// <returns></returns> public DmdModule CreateModule(DmdAssembly assembly, object comMetadata, DmdDynamicModuleHelper dynamicModuleHelper, DmdDispatcher dispatcher, bool isInMemory, bool isDynamic, string fullyQualifiedName) { if (comMetadata == null) { throw new ArgumentNullException(nameof(comMetadata)); } if (dynamicModuleHelper == null) { throw new ArgumentNullException(nameof(dynamicModuleHelper)); } if (dispatcher == null) { throw new ArgumentNullException(nameof(dispatcher)); } var mdi = comMetadata as Impl.COMD.IMetaDataImport2 ?? throw new ArgumentException("Only IMetaDataImport is supported"); return(CreateModule(assembly, () => new DmdLazyMetadataBytesCom(mdi, dynamicModuleHelper, dispatcher), isInMemory, isDynamic, fullyQualifiedName)); }
internal TemporaryAssemblyDisposable(DmdAssembly assembly) { this.assembly = assembly ?? throw new ArgumentNullException(nameof(assembly)); assembly.AppDomain.Add(assembly); }
/// <summary> /// Adds an assembly. It gets removed when the return value's <see cref="IDisposable.Dispose"/> method gets called /// </summary> /// <param name="assembly">Assembly to add</param> /// <returns></returns> public TemporaryAssemblyDisposable AddTemporaryAssembly(DmdAssembly assembly) => new TemporaryAssemblyDisposable(assembly);
/// <summary> /// Removes an assembly /// </summary> /// <param name="assembly">Assembly to remove</param> public abstract void Remove(DmdAssembly assembly);
/// <summary> /// Adds an assembly /// </summary> /// <param name="assembly">Assembly to add</param> public abstract void Add(DmdAssembly assembly);
/// <summary> /// Adds a module to an existing assembly /// </summary> /// <param name="assembly">Assembly</param> /// <param name="address">Address of the PE file</param> /// <param name="size">Size of the PE file</param> /// <param name="isFileLayout">true if file layout, false if memory layout</param> /// <param name="isInMemory">true if the module is in memory (<see cref="DmdModule.IsInMemory"/>)</param> /// <param name="isDynamic">true if it's a dynamic module (types can be added at runtime) (<see cref="DmdModule.IsDynamic"/>)</param> /// <param name="fullyQualifiedName">The fully qualified name of the module (<see cref="DmdModule.FullyQualifiedName"/>). See <see cref="DmdModule.GetFullyQualifiedName(bool, bool, string)"/></param> /// <returns></returns> public DmdModule CreateModule(DmdAssembly assembly, IntPtr address, uint size, bool isFileLayout, bool isInMemory, bool isDynamic, string fullyQualifiedName) => CreateModule(assembly, () => new DmdLazyMetadataBytesPtr(address, size, isFileLayout), isInMemory, isDynamic, fullyQualifiedName);
/// <summary> /// Adds a module to an existing assembly /// </summary> /// <param name="assembly">Assembly</param> /// <param name="getMetadata">Called to provide the metadata</param> /// <param name="isInMemory">true if the module is in memory (<see cref="DmdModule.IsInMemory"/>)</param> /// <param name="isDynamic">true if it's a dynamic module (types can be added at runtime) (<see cref="DmdModule.IsDynamic"/>)</param> /// <param name="fullyQualifiedName">The fully qualified name of the module (<see cref="DmdModule.FullyQualifiedName"/>). See <see cref="DmdModule.GetFullyQualifiedName(bool, bool, string)"/></param> /// <returns></returns> public abstract DmdModule CreateModule(DmdAssembly assembly, Func <DmdLazyMetadataBytes> getMetadata, bool isInMemory, bool isDynamic, string fullyQualifiedName);