예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }