コード例 #1
0
ファイル: DmdAppDomain.cs プロジェクト: wagnerhsu/tools-dnSpy
        /// <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));
        }
コード例 #2
0
 internal DmdLazyMetadataBytesCom(Impl.COMD.IMetaDataImport2 metaDataImport, DmdDynamicModuleHelper dynamicModuleHelper, DmdDispatcher dispatcher)
 {
     MetaDataImport      = metaDataImport ?? throw new ArgumentNullException(nameof(metaDataImport));
     DynamicModuleHelper = dynamicModuleHelper ?? throw new ArgumentNullException(nameof(dynamicModuleHelper));
     Dispatcher          = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
 }
コード例 #3
0
        /// <summary>
        /// Creates an assembly. The first created assembly must be the corlib (<see cref="DmdAppDomain.CorLib"/>)
        /// </summary>
        /// <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>
        /// <param name="assemblyLocation">Location of the assembly or an empty string (<see cref="DmdAssembly.Location"/>)</param>
        /// <returns></returns>
        public DmdAssembly CreateAssembly(object comMetadata, DmdDynamicModuleHelper dynamicModuleHelper, DmdDispatcher dispatcher, bool isInMemory, bool isDynamic, string fullyQualifiedName, string?assemblyLocation = null)
        {
            if (comMetadata is null)
            {
                throw new ArgumentNullException(nameof(comMetadata));
            }
            if (dynamicModuleHelper is null)
            {
                throw new ArgumentNullException(nameof(dynamicModuleHelper));
            }
            if (dispatcher is null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }
            var mdi = comMetadata as Impl.COMD.IMetaDataImport2 ?? throw new ArgumentException("Only IMetaDataImport is supported");

            return(CreateAssembly(() => new DmdLazyMetadataBytesCom(mdi, dynamicModuleHelper, dispatcher), isInMemory, isDynamic, fullyQualifiedName, assemblyLocation ?? string.Empty));
        }
コード例 #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <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>
 public DmdLazyMetadataBytesCom(object comMetadata, DmdDynamicModuleHelper dynamicModuleHelper, DmdDispatcher dispatcher)
 {
     MetaDataImport      = comMetadata as Impl.COMD.IMetaDataImport2 ?? throw new ArgumentException("Only " + nameof(Impl.COMD.IMetaDataImport2) + " is supported");
     DynamicModuleHelper = dynamicModuleHelper ?? throw new ArgumentNullException(nameof(dynamicModuleHelper));
     Dispatcher          = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
 }