protected override Assembly Generate() { var nt = Host.NameTable; var mscorlib = Host.LoadAssembly(Host.CoreAssemblySymbolicIdentity); var assembly = new Assembly { Name = nt.GetNameFor(AssemblyName), ModuleName = nt.GetNameFor(DllName), Kind = ModuleKind.DynamicallyLinkedLibrary, TargetRuntimeVersion = mscorlib.TargetRuntimeVersion, MetadataFormatMajorVersion = 2 }; assembly.AssemblyReferences.Add(mscorlib); var rootNamespace = new RootUnitNamespace(); assembly.UnitNamespaceRoot = rootNamespace; rootNamespace.Unit = assembly; // define module DefineModule(assembly, rootNamespace); var typeA = GenerateTypeA(rootNamespace); assembly.AllTypes.Add(typeA); var baseType = GenericTypeInstance.GetGenericTypeInstance(typeA, new[] { Host.PlatformType.SystemString }, Host.InternFactory); var typeB = GenerateTypeB(rootNamespace, baseType); assembly.AllTypes.Add(typeB); return(assembly); }
private static Type ReadGenericInst(ModuleReader module, ByteReader br, IGenericContext context) { Type type; switch (br.ReadByte()) { case ELEMENT_TYPE_CLASS: type = ReadTypeDefOrRefEncoded(module, br, context).MarkNotValueType(); break; case ELEMENT_TYPE_VALUETYPE: type = ReadTypeDefOrRefEncoded(module, br, context).MarkValueType(); break; default: throw new BadImageFormatException(); } if (!type.__IsMissing && !type.IsGenericTypeDefinition) { throw new BadImageFormatException(); } int genArgCount = br.ReadCompressedInt(); Type[] args = new Type[genArgCount]; Type[][] reqmod = null; Type[][] optmod = null; for (int i = 0; i < genArgCount; i++) { // LAMESPEC the Type production (23.2.12) doesn't include CustomMod* for genericinst, but C++ uses it, the verifier allows it and ildasm also supports it CustomModifiers mods = ReadCustomModifiers(module, br, context); if (mods.required != null || mods.optional != null) { if (reqmod == null) { reqmod = new Type[genArgCount][]; optmod = new Type[genArgCount][]; } reqmod[i] = mods.required; optmod[i] = mods.optional; } args[i] = ReadType(module, br, context); } return(GenericTypeInstance.Make(type, args, reqmod, optmod)); }