private void TestBlock(Type delegateType, Type referenceType, bool is64Bits) { counter++; DynamicAssembly dynamicAssembly = new DynamicAssembly(DynamicAssemblyHelper.GetAssemblyName(this, counter), "MyModule"); BlockGenerator generator = new BlockGenerator(dynamicAssembly, is64Bits); Type proxyType = generator.DefineBlockProxy(delegateType); try { String file = dynamicAssembly.Save(); Assembly assembly = Assembly.LoadFile(file); Type type = assembly.GetTypes().Single(t => t.FullName == proxyType.FullName); DynamicAssemblyHelper.Compare(referenceType, type); } catch (Exception ex) { Assert.Fail("Type retrieval failed with " + ex); } }
private Block GetBlock(Delegate block) { if (this.generator == null) { DynamicAssembly assembly = new DynamicAssembly("BlockGeneratedTests", "MyModule"); this.generator = new BlockGenerator(assembly, false); } Type delegateType = block.GetType(); Type blockProxyType; lock (this.blocks) { if (!this.blocks.TryGetValue(delegateType, out blockProxyType)) { blockProxyType = this.generator.DefineBlockProxy(delegateType); this.blocks[delegateType] = blockProxyType; } } return (Block)Activator.CreateInstance(blockProxyType, block); }