コード例 #1
0
        public static ModuleDefinition CreateModule(string name, ModuleParameters parameters)
        {
            Mixin.CheckName(name);
            Mixin.CheckParameters(parameters);

            var module = new ModuleDefinition {
                Name            = name,
                kind            = parameters.Kind,
                timestamp       = parameters.Timestamp ?? Mixin.GetTimestamp(),
                Runtime         = parameters.Runtime,
                architecture    = parameters.Architecture,
                mvid            = Guid.NewGuid(),
                Attributes      = ModuleAttributes.ILOnly,
                Characteristics = (ModuleCharacteristics)0x8540,
            };

            if (parameters.AssemblyResolver != null)
            {
                module.assembly_resolver = Disposable.NotOwned(parameters.AssemblyResolver);
            }

            if (parameters.MetadataResolver != null)
            {
                module.metadata_resolver = parameters.MetadataResolver;
            }

#if !READ_ONLY
            if (parameters.MetadataImporterProvider != null)
            {
                module.metadata_importer = parameters.MetadataImporterProvider.GetMetadataImporter(module);
            }
            if (parameters.ReflectionImporterProvider != null)
            {
                module.reflection_importer = parameters.ReflectionImporterProvider.GetReflectionImporter(module);
            }
#endif

            if (parameters.Kind != ModuleKind.NetModule)
            {
                var assembly = new AssemblyDefinition();
                module.assembly      = assembly;
                module.assembly.Name = CreateAssemblyName(name);
                assembly.main_module = module;
            }

            module.Types.Add(new TypeDefinition(string.Empty, "<Module>", TypeAttributes.NotPublic));

            return(module);
        }
コード例 #2
0
ファイル: AssemblyDefinition.cs プロジェクト: zwinter/ET
        public static AssemblyDefinition CreateAssembly(AssemblyNameDefinition assemblyName, string moduleName, ModuleParameters parameters)
        {
            if (assemblyName == null)
            {
                throw new ArgumentNullException("assemblyName");
            }
            if (moduleName == null)
            {
                throw new ArgumentNullException("moduleName");
            }
            Mixin.CheckParameters(parameters);
            if (parameters.Kind == ModuleKind.NetModule)
            {
                throw new ArgumentException("kind");
            }

            var assembly = ModuleDefinition.CreateModule(moduleName, parameters).Assembly;

            assembly.Name = assemblyName;

            return(assembly);
        }