public void InaccessibleFields() { dynamic d = new TypeWithFields(); Assert.Throws <RuntimeBinderException>(() => d.Protected); Assert.Throws <RuntimeBinderException>(() => d.PrivateProtected); Assert.Throws <RuntimeBinderException>(() => d.Private); }
public void AccessibleFields() { dynamic d = new TypeWithFields(); Assert.Equal(1, d.Public); Assert.Equal(3, d.Internal); Assert.Equal(4, d.ProtectedInternal); }
public void SetFieldByName_is_correct() { const int number = 12; const string text = "test_text"; var obj = new TypeWithFields(number, text); var type = obj.GetType(); type.SetFieldValueByName(obj, "_number", number * 2); type.SetFieldValueByName(obj, "_text", text + text); obj.Number.ShouldBe(24); obj._text.ShouldBe("test_texttest_text"); }
public void GetFieldsValues_is_correct() { const int number = 12; const string text = "test_text"; var obj = new TypeWithFields(number, text); var type = obj.GetType(); var fields = type.GetFieldsValues(obj); fields.Count.ShouldBe(2); fields["_number"].ShouldBe(number); fields["_text"].ShouldBe(text); }
public void GetFieldByName_is_correct() { const int number = 12; const string text = "test_text"; var obj = new TypeWithFields(number, text); var type = obj.GetType(); type .GetFieldValueByName(obj, "_number") .ShouldBe(number); type .GetFieldValueByName(obj, "_text") .ShouldBe(text); }