public void GetAndSetValueInt() { var tmp = new PublicClassPrivateFields(); object value = ReflectionHelper.GetNonPublicIntFiledValue(tmp, "privateInt", tmp.GetType()); Assert.IsNotNull(value); Assert.IsTrue(value is Int32); Assert.AreEqual(value, 100); ReflectionHelper.SetNonPublicIntFiledValue(tmp, 666, "privateInt", tmp.GetType()); value = ReflectionHelper.GetNonPublicIntFiledValue(tmp, "privateInt", tmp.GetType()); Assert.IsNotNull(value); Assert.IsTrue(value is Int32); Assert.AreEqual(value, 666); }
public void GetAndSetValueString() { var tmp = new PublicClassPrivateFields(); object value = ReflectionHelper.GetNonPublicIntFiledValue(tmp, "privateString", tmp.GetType()); Assert.IsNotNull(value); Assert.IsTrue(value is string); Assert.AreEqual(value, "100"); ReflectionHelper.SetNonPublicIntFiledValue(tmp, "privateString", "privateString", tmp.GetType()); value = ReflectionHelper.GetNonPublicIntFiledValue(tmp, "privateString", tmp.GetType()); Assert.IsNotNull(value); Assert.IsTrue(value is string); Assert.AreEqual(value, "privateString"); }