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); } }
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); } }
/// <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) { }
public CategoryGenerator (DynamicAssembly assembly, bool is64Bits) : base(assembly, is64Bits) { }
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); } }
/// <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) { }
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); }