Example #1
0
 public Swindler(Type @class, string memberName, object cheat)
 {
     _accessor      = new TypeAccessor(@class);
     _memberName    = memberName;
     _originalValue = _accessor.GetStaticFieldOrProperty(memberName);
     _accessor.SetStaticFieldOrProperty(_memberName, cheat);
 }
Example #2
0
        public void Accessor_Protected_Type_Property_OnImplementation()
        {
            var typeAcc = new TypeAccessor(typeof(AccessorTestObject));

            var origValue = (int)typeAcc.GetStaticProperty("ProtectedStaticProperty");

            typeAcc.SetStaticProperty("ProtectedStaticProperty", origValue + 1);
            var actualValue = (int)typeAcc.GetStaticProperty("ProtectedStaticProperty");

            Assert.AreEqual(origValue + 1, actualValue);

            typeAcc.SetStaticFieldOrProperty("ProtectedStaticProperty", origValue - 1);
            actualValue = (int)typeAcc.GetStaticFieldOrProperty("ProtectedStaticProperty");
            Assert.AreEqual(origValue - 1, actualValue);
        }
Example #3
0
        public void Accessor_Public_Type_Field()
        {
            var typeAcc = new TypeAccessor(typeof(AccessorTestObject));

            var origValue = (int)typeAcc.GetStaticField("_staticPublicField");

            typeAcc.SetStaticField("_staticPublicField", origValue + 1);
            var actualValue = (int)typeAcc.GetStaticField("_staticPublicField");

            Assert.AreEqual(origValue + 1, actualValue);

            typeAcc.SetStaticFieldOrProperty("_staticPublicField", origValue - 1);
            actualValue = (int)typeAcc.GetStaticFieldOrProperty("_staticPublicField");
            Assert.AreEqual(origValue - 1, actualValue);
        }
Example #4
0
 public void Dispose()
 {
     _accessor.SetStaticFieldOrProperty(_memberName, _originalValue);
 }