示例#1
0
        private void TestWrapper(int number, Type protocolType, Type referenceType)
        {
            DynamicAssembly assembly = new DynamicAssembly(DynamicAssemblyHelper.GetAssemblyName(this, number), "MyModule");

            WrapperGenerator wrapperGenerator = new WrapperGenerator(assembly, false);
            Type proxyType = wrapperGenerator.DefineWrapperProxy(protocolType);

            try
            {
                assembly.Save();
                Type type = assembly.GetType(proxyType.FullName);
                DynamicAssemblyHelper.Compare(referenceType, type);
            }
            catch (Exception ex)
            {
                Assert.Fail("Type retrieval failed with " + ex);
            }
        }
示例#2
0
        private void TestClass(Type classType, Type referenceType, bool is64Bits)
        {
            counter++;

            DynamicAssembly assembly = new DynamicAssembly(DynamicAssemblyHelper.GetAssemblyName(this, counter), "MyModule");

            MethodTuple[] extensionMethods = Bridge.CollectStaticMethods(classType);
            Assert.IsTrue(Array.TrueForAll(extensionMethods, m => m.MethodInfo.IsStatic));

            CategoryGenerator generator = new CategoryGenerator(assembly, is64Bits);
            Type proxyType = generator.DefineCategoryProxy(classType, extensionMethods);

            try
            {
                assembly.Save();
                Type type = assembly.GetType(proxyType.FullName);
                DynamicAssemblyHelper.Compare(referenceType, type);
            }
            catch (Exception ex)
            {
                Assert.Fail("Type retrieval failed with " + ex);
            }
        }
示例#3
0
		/// <summary>
		///   Initializes a new instance of the <see cref = "BlockGenerator" /> class.
		/// </summary>
		/// <param name = "assembly">The assembly.</param>
		/// <param name = "is64Bits"></param>
		public BlockGenerator (DynamicAssembly assembly, bool is64Bits) : base(assembly, is64Bits)
		{
		}
示例#4
0
		public CategoryGenerator (DynamicAssembly assembly, bool is64Bits) : base(assembly, is64Bits)
		{
		}
示例#5
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);
            }
        }
示例#6
0
		/// <summary>
		///   Initializes a new instance of the <see cref = "WrapperGenerator" /> class.
		/// </summary>
		/// <param name = "assembly">The assembly.</param>
		/// <param name = "is64Bits"></param>
		public WrapperGenerator (DynamicAssembly assembly, bool is64Bits) : base(assembly, is64Bits)
		{
		}
示例#7
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);
        }