public void AddForwardingProperty() { var proxyBuilder = new ForwardingProxyBuilder("AddForwardingProperty", ModuleScope, typeof(ProxiedChildGeneric <ProxiedChild, double>), new Type[0]); var propertyInfo = typeof(ProxiedChildGeneric <ProxiedChild, double>).GetProperty("MutableName"); var propertyEmitter = proxyBuilder.AddForwardingProperty(propertyInfo); // Added by FS Assert.That(propertyEmitter.Name, Is.EqualTo(propertyInfo.Name)); Assert.That(propertyEmitter.PropertyType, Is.SameAs(propertyInfo.PropertyType)); // Create proxy instance, initializing it with class to be proxied var proxied = new ProxiedChildGeneric <ProxiedChild, double> ("PCG", new ProxiedChild("PC"), 123.456); //object proxy = proxyBuilder.CreateInstance (proxied); var proxyType = proxyBuilder.BuildProxyType(); //object proxy = proxyBuilder.CreateInstance (proxied); object proxy = Activator.CreateInstance(proxyType, proxied); Assert.That(proxied.MutableName, Is.EqualTo("ProxiedChild: PCG")); //var proxyPropertyInfo = proxy.GetType ().GetProperty ("MutableName"); var proxyPropertyInfo = proxyType.GetProperty("MutableName"); AssertPropertyInfoEqual(proxyPropertyInfo, propertyInfo); Assert.That(proxyPropertyInfo.GetValue(proxy, null), Is.EqualTo("ProxiedChild: PCG")); proxied.MutableName = "PCG_Changed"; Assert.That(proxyPropertyInfo.GetValue(proxy, null), Is.EqualTo("ProxiedChild: PCG_Changed")); proxyPropertyInfo.SetValue(proxy, "PCG_Changed_Proxy", null); Assert.That(proxied.MutableName, Is.EqualTo("ProxiedChild: PCG_Changed_Proxy")); Assert.That(proxyPropertyInfo.GetValue(proxy, null), Is.EqualTo("ProxiedChild: PCG_Changed_Proxy")); }
public void AddForwardingMethod_GenericClass() { var proxyBuilder = new ForwardingProxyBuilder("AddForwardingMethod_GenericClass", ModuleScope, typeof(ProxiedChildGeneric <ProxiedChild, double>), new Type[0]); var methodInfo = typeof(ProxiedChildGeneric <ProxiedChild, double>).GetMethod("ToStringKebap"); var methodEmitter = proxyBuilder.AddForwardingMethod(methodInfo); // Create proxy instance, initializing it with class to be proxied var proxied = new ProxiedChildGeneric <ProxiedChild, double> ("PCG", new ProxiedChild("PC"), 123.456); object proxy = proxyBuilder.CreateInstance(proxied); // Added by FS AssertMethodInfoEqual(methodEmitter.MethodBuilder, methodInfo); var proxyMethodInfo = proxy.GetType().GetMethod("ToStringKebap"); AssertMethodInfoEqual(proxyMethodInfo, methodInfo); Assert.That(proxyMethodInfo.Invoke(proxy, new object[] { 9800 }), Is.EqualTo("ProxiedChild: PCG_[Proxied: PC]_123.456_9800")); }