public void GetPropertyValue() { var test = new TestRelfectionClass { Prop1 = null, Prop2 = "asdsada" }; Assert.Equal(test.Prop1, ReflectionHelper.GetPropertyValue(test, nameof(test.Prop1))); Assert.Equal(test.Prop2, ReflectionHelper.GetPropertyValue(test, nameof(test.Prop2))); }
public void SetProtectedFieldValue() { string newValue = "new value 1"; var test = new TestRelfectionClass { }; ReflectionHelper.SetNonPublicField(test, "field2", newValue); Assert.Equal(newValue, ReflectionHelper.GetNonPublicField(test, "field2")); ReflectionHelper.SetNonPublicField(test, "field2", null); Assert.Null(ReflectionHelper.GetNonPublicField(test, "field2")); }
public void SetPropertyValue() { string newProp1 = "new value 1"; var test = new TestRelfectionClass { Prop1 = null, Prop2 = "asdsada" }; ReflectionHelper.SetPropertyValue(test, nameof(test.Prop1), newProp1); ReflectionHelper.SetPropertyValue(test, nameof(test.Prop2), null); Assert.Equal(newProp1, test.Prop1); Assert.Null(test.Prop2); }