public void TestSerializedSignatureWithReferenceToMDIntArray() { var typeInInitialContext = _context.GetWellKnownType(WellKnownType.Int32).MakeArrayType(3); // Create assembly with reference to interesting type TypeSystemMetadataEmitter metadataEmitter = new TypeSystemMetadataEmitter(new System.Reflection.AssemblyName("Lookup"), _context); var token = metadataEmitter.GetTypeRef(typeInInitialContext); Stream peStream = new MemoryStream(); metadataEmitter.SerializeToStream(peStream); peStream.Seek(0, SeekOrigin.Begin); // Create new TypeSystemContext with just created assembly inside var lookupContext = new TestTypeSystemContext(TargetArchitecture.X64); var systemModule = lookupContext.CreateModuleForSimpleName("CoreTestAssembly"); lookupContext.SetSystemModule(systemModule); lookupContext.CreateModuleForSimpleName("Lookup", peStream); // Use generated assembly to trigger a load through the token created above and verify that it loads correctly var ilLookupModule = (EcmaModule)lookupContext.GetModuleForSimpleName("Lookup"); TypeDesc int32ArrayFromLookup = ilLookupModule.GetType(token); var typeInLookupContext = lookupContext.GetWellKnownType(WellKnownType.Int32).MakeArrayType(3); Assert.Equal(typeInLookupContext, int32ArrayFromLookup); }
public void TestSerializedSignatureWithArrayShapes() { MetadataType modOptTester = _testModule.GetType("", "ModOptTester"); MethodDesc methodWithInterestingShapes = modOptTester.GetMethods().Single(m => string.Equals(m.Name, "Method4")); // Create assembly with reference to interesting method TypeSystemMetadataEmitter metadataEmitter = new TypeSystemMetadataEmitter(new System.Reflection.AssemblyName("Lookup"), _context); var token = metadataEmitter.GetMethodRef(methodWithInterestingShapes); Stream peStream = new MemoryStream(); metadataEmitter.SerializeToStream(peStream); peStream.Seek(0, SeekOrigin.Begin); // Create new TypeSystemContext with just created assembly inside var lookupContext = new TestTypeSystemContext(TargetArchitecture.X64); var systemModule = lookupContext.CreateModuleForSimpleName("CoreTestAssembly"); lookupContext.SetSystemModule(systemModule); lookupContext.CreateModuleForSimpleName("Lookup", peStream); // Use generated assembly to trigger a load through the token created above and verify that it loads correctly var ilLookupModule = (EcmaModule)lookupContext.GetModuleForSimpleName("Lookup"); MethodDesc method4 = ilLookupModule.GetMethod(token); Assert.Equal("Method4", method4.Name); }
public void TestExplicitOverride() { // // Test that explicit virtual method overriding works. // var ilModule = _context.GetModuleForSimpleName("ILTestAssembly"); var explicitOverrideClass = ilModule.GetType("VirtualFunctionOverride", "ExplicitOverride"); var myGetHashCodeMethod = explicitOverrideClass.GetMethod("MyGetHashCode", null); var objectGetHashCodeMethod = _context.GetWellKnownType(WellKnownType.Object).GetMethod("GetHashCode", null); var foundOverride = explicitOverrideClass.FindVirtualFunctionTargetMethodOnObjectType(objectGetHashCodeMethod); Assert.Equal(myGetHashCodeMethod, foundOverride); }
public ILDisassemblerTests() { _context = new TestTypeSystemContext(TargetArchitecture.X64); var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(systemModule); _testModule = _context.GetModuleForSimpleName("ILTestAssembly"); }
public ILDisassemblerTests() { _context = new TestTypeSystemContext(TargetArchitecture.X64); var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(systemModule); _testModule = _context.GetModuleForSimpleName("ILTestAssembly"); }
public SignatureTests(ITestOutputHelper output) { _output = output; _context = new TestTypeSystemContext(TargetArchitecture.X64); var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(systemModule); _testModule = _context.GetModuleForSimpleName("ILTestAssembly"); }
public void TestRvaStatics() { // // Test that an RVA mapped field has the right value for the offset. // var ilModule = _context.GetModuleForSimpleName("ILTestAssembly"); var t = ilModule.GetType("StaticFieldLayout", "RvaStatics"); var field = t.GetField("StaticInitedInt"); Assert.True(field.HasRva); byte[] rvaData = ((EcmaField)field).GetFieldRvaData(); Assert.Equal(4, rvaData.Length); int value = BinaryPrimitives.ReadInt32LittleEndian(rvaData); Assert.Equal(0x78563412, value); }