예제 #1
0
        public void InaccessibleFields()
        {
            dynamic d = new TypeWithFields();

            Assert.Throws <RuntimeBinderException>(() => d.Protected);
            Assert.Throws <RuntimeBinderException>(() => d.PrivateProtected);
            Assert.Throws <RuntimeBinderException>(() => d.Private);
        }
예제 #2
0
        public void AccessibleFields()
        {
            dynamic d = new TypeWithFields();

            Assert.Equal(1, d.Public);
            Assert.Equal(3, d.Internal);
            Assert.Equal(4, d.ProtectedInternal);
        }
예제 #3
0
        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");
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }