Exemple #1
0
        public void AutoImplementStubProperty()
        {
            Type        tA = typeof(PA);
            TypeBuilder bA = CreateTypeBuilder(tA);

            EmitHelper.ImplementStubProperty(bA, tA.GetProperty("PublicWriteableValue"), true);
            EmitHelper.ImplementStubProperty(bA, tA.GetProperty("ProtectedWriteableValue"), true);
            Type builtTypeA = bA.CreateTypeInfo().AsType();
            PA   oA         = (PA)Activator.CreateInstance(builtTypeA);

            oA.PublicWriteableValue = 4548;
            oA.SetProtectedValues(2121);
            Assert.That(oA.PublicWriteableValue, Is.EqualTo(4548));
            Assert.That(oA.ProtectedWriteableValue, Is.EqualTo(2121));

            Type        tB = typeof(PB);
            TypeBuilder bB = CreateTypeBuilder(tB);

            EmitHelper.ImplementStubProperty(bB, tB.GetProperty("PublicWriteableValue"), true);
            EmitHelper.ImplementStubProperty(bB, tB.GetProperty("ProtectedWriteableValue"), true);
            Type builtTypeB = bB.CreateTypeInfo().AsType();
            PB   oB         = (PB)Activator.CreateInstance(builtTypeB);

            oB.PublicWriteableValue = 4548;
            oB.SetProtectedValues(2121);
            Assert.That(oB.PublicWriteableValue, Is.EqualTo(4548));
            Assert.That(oB.ProtectedWriteableValue, Is.EqualTo(2121));
            Assert.That(oB.PublicProperty, Is.EqualTo(2121 % 255));
        }