Beispiel #1
0
        public void NullableTest()
        {
            var m  = new NullableClass();
            var di = new DynamicInstance(m);

            di.Set("X", 5);
            Assert.Equal(m.X, 5);
            di.Set("X", "6");
            Assert.Equal(m.X, 6);
            di.Set("X", null);
            Assert.Null(m.X);
        }
Beispiel #2
0
        public void CreateFieldSetterTest()
        {
            var m = new Fields.Model()
            {
                Public = "a"
            };
            var di = new DynamicInstance(m);

            di.Set("Public", "p-s-v-1");
            di.Set("Private", "p-s-v-2");
            Assert.Equal("p-s-v-1", m.Public);
            Assert.Equal("p-s-v-2", di.Get("Private"));

            di = new DynamicInstance(typeof(Fields.Model));
            di.Set("PublicStatic", "p-s-v-3");
            Assert.Equal("p-s-v-3", di.Get("PublicStatic"));
        }
Beispiel #3
0
        public void CreatePropertySetterTest()
        {
            var m = new Properties.Model()
            {
                Public = "a"
            };
            var di = new DynamicInstance(m);

            di.Set("Public", "p-s-v-1");
            di.Set("Private", "p-s-v-2");
            Assert.Equal("p-s-v-1", m.Public);
            Assert.Equal("p-s-v-2", di.Get("Private"));

            di.Set("PublicArray", new string[] { "1", "2", "3" });
            Assert.Equal(new string[] { "1", "2", "3" }, m.PublicArray);

            di = new DynamicInstance(typeof(Properties.Model));
            di.Set("PublicStatic", "p-s-v-3");
            Assert.Equal("p-s-v-3", di.Get("PublicStatic"));
        }
Beispiel #4
0
        public void StructTest()
        {
            var box = DynamicFactory.CreateInstance(typeof(MyStruct));

            DynamicInstance di = new DynamicInstance(box);

            di.Set("Field", 6);
            di.Set("Property", "AAA");
            di.Set("ChildStruct", new ChildStruct()
            {
                Field = 12
            });
            var str = (MyStruct)box;

            Assert.Equal(6, str.Field);
            Assert.Equal("AAA", str.Property);
            Assert.Equal(12, str.ChildStruct.Field);

            di = new DynamicInstance(str);
            Assert.Equal(6, di.Get("Field"));
            Assert.Equal("AAA", di.Get("Property"));
            Assert.Equal(12, ((ChildStruct)di.Get("ChildStruct")).Field);
        }