Example #1
0
        public void DynamicInstanceTest()
        {
            var di = new DynamicInstance(new Sum());

            Assert.Equal("1", di.Get("Field"));
            Assert.Equal("1", di.Get("Property"));
            di = new DynamicInstance(new Sum(), typeof(Father));
            Assert.Equal("2", di.Get("Field"));
            Assert.Equal("1", di.Get("Property"));
        }
Example #2
0
        public void CreateFieldGetterTest()
        {
            var di = new DynamicInstance(new Fields.Model()
            {
                Public = "a"
            });

            Assert.Equal("a", di.Get("Public"));
            Assert.Null(di.Get("Private"));
            di = new DynamicInstance(new Fields.Model <int>()
            {
                Public = 5
            });
            Assert.Equal(5, di.Get("Public"));

            di = new DynamicInstance(typeof(Fields.Model));
            Fields.Model.PublicStatic = "p-s-v";
            Assert.Equal("p-s-v", di.Get("PublicStatic"));
        }
Example #3
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);
        }
Example #4
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"));
        }
Example #5
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"));
        }