Beispiel #1
0
        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"));
        }
Beispiel #2
0
        public void AddForwardingProperty_WriteOnlyProperty()
        {
            Type proxiedType  = typeof(Proxied);
            var  proxyBuilder = new ForwardingProxyBuilder("AddForwardingProperty_WriteOnlyProperty", ModuleScope, proxiedType, new Type[0]);

            var propertyInfo    = proxiedType.GetProperty("WriteonlyName");
            var propertyEmitter = proxyBuilder.AddForwardingProperty(propertyInfo);

            // Added by FS
            Assert.That(propertyEmitter.Name, Is.EqualTo(propertyInfo.Name));
            Assert.That(propertyEmitter.PropertyType, Is.SameAs(propertyInfo.PropertyType));

            Type proxyType         = proxyBuilder.BuildProxyType();
            var  proxyPropertyInfo = proxyType.GetProperty("WriteonlyName");

            Assert.That(proxyPropertyInfo.CanRead, Is.False);
            Assert.That(proxyPropertyInfo.CanWrite, Is.True);
        }