예제 #1
0
        public void InstanceOf()
        {
            ClassOf    I1class = new ClassOf(typeof(I1));
            InstanceOf I1ins   = new InstanceOf(I1class.CreateInstance());

            Assert.That((string)I1ins.Method("f1") == "my name is f1");

            //SetProperty()
            I1ins.SetProperty("p1", "my name is p1");
            //Assert.That(I1ins.SetProperty("p2", "my name is p2"), Throws.Exception.TypeOf(Of MissingMethodException))
            I1ins.SetProperty("p3", "my name is p3");

            //GetProperty()
            Assert.That((string)I1ins.GetProperty("p1") == "my name is p1");
            Assert.That((string)I1ins.GetProperty("p2") == "my name is p2");
            //Assert.That(I1ins.GetProperty("p3"), Throws.Exception)


            ClassOf    I2class = new ClassOf(typeof(I2 <>), typeof(string));
            InstanceOf I2ins   = new InstanceOf(I2class.CreateInstance());

            //SetProperty()
            I2ins.SetProperty("p1", "my name is p1.");

            //GetProperty()
            Assert.That((string)I2ins.GetProperty("p1") == "my name is p1.");
        }
예제 #2
0
        public void ClassOf()
        {
            ClassOf c1         = new ClassOf(Type.GetType("FoundationTester.T1"));
            object  c1instance = c1.CreateInstance();

            Assert.That(c1instance.GetType() == typeof(T1));
            Assert.That((string)c1.Method("f1") == "my name is f1");
            // Assert.That(c1.Function("notExistsFuncName"), Throws.Exception.TypeOf(Of MissingMethodException))

            // SetProperty()
            c1.SetProperty("p1", "my name is p1");
            // Assert.That(c1.SetProperty("p2", "my name is p2"), Throws.Exception.TypeOf(Of MissingMethodException))
            c1.SetProperty("p3", "my name is p3");

            // GetProperty()
            Assert.That((string)c1.GetProperty("p1") == "my name is p1");
            Assert.That((string)c1.GetProperty("p2") == "my name is p2");
            // Assert.That(c1.GetProperty("p3"), Throws.Exception)

            ClassOf c2         = new ClassOf(Type.GetType("FoundationTester.T2`1"), Type.GetType("System.String"));
            object  c2instance = c2.CreateInstance();

            Assert.That(c2instance.GetType() == typeof(T2 <string>));

            // SetProperty()
            c2.SetProperty("p1", "my name is p1.");

            // GetProperty()
            Assert.That((string)c2.GetProperty("p1") == "my name is p1.");

            ClassOf c3         = new ClassOf(Type.GetType("FoundationTester.T3`2"), Type.GetType("System.String"), Type.GetType("System.Int32"));
            object  c3instance = c3.CreateInstance();

            Assert.That(c3instance.GetType() == typeof(T3 <string, int>));

            ClassOf c4         = new ClassOf(Type.GetType("FoundationTester.T4`1"), Type.GetType("System.Int32"));
            object  c4instance = c4.CreateInstance(100);

            Assert.That(c4instance.GetType() == typeof(T4 <int>));
            // Assert.That(c4.CreateInstance(), Throws.TypeOf(Of MissingMethodException))
        }