예제 #1
0
        public void TestDynamicInterfaceAgainstAnonymousObject()
        {
            var di = new DynamicInterface();

            // proves that it reuses generated ProxyClasses.
            for (int i = 0; i < 10; i++)
            {
                var idyn2 = di.Create <IDynTest>(new {
                    One = new Action(() => {}),
                    Two = new Func <bool>(() => { return(true); })
                });

                Assert.True(idyn2.IsMethodImplemented("One"));
                Assert.True(idyn2.IsMethodImplemented("Two"));
                Assert.False(idyn2.IsMethodImplemented("Three"));
                Assert.False(idyn2.IsMethodImplemented("Four"));
                Assert.False(idyn2.IsMethodImplemented("Five"));


                idyn2.One();

                Assert.True(idyn2.Two());
                Assert.Equal(null, idyn2.Four(4));
            }
        }
예제 #2
0
        public void CreateTypeWithBadArguments()
        {
            var di = new DynamicInterface();

            Assert.Throws <Exception>(() => {
                di.Create <IDynTest>(typeof(object), typeof(File));
            });
        }
예제 #3
0
 public void TestDynamicInterfaceRequired()
 {
     using (CaptureConsole) {
         Assert.Throws <Exception>(() => {
             var idyn3 = DynamicInterface.DynamicCast <IDynTest>(new {
                 One = new Action(() => {})
             });
         });
     }
 }
예제 #4
0
        public void TestDynamicInterfaceRequired()
        {
            var di = new DynamicInterface();

            Assert.Throws <Exception>(() => {
                var idyn3 = di.Create <IDynTest>(new {
                    One = new Action(() => {})
                });
            });
        }
예제 #5
0
 private void OnTriggerExit2D(Collider2D collision)
 {
     if (collision.gameObject.CompareTag("Player"))
     {
         Destroy(screen);
         screen  = null;
         chestUi = null;
         // chestUi.UnsetSlots();
         // inventory = collision.gameObject.GetComponent<Player>().inventory;
     }
 }
예제 #6
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            GameObject chest = Instantiate(screenPrefab, canvas.transform);
            screen = chest;
            RectTransform chestRect = chest.GetComponent <RectTransform>();
            chest.SetActive(true);
            //  chest.transform.position = new Vector3(950, 50, 0);
            chestRect.localPosition = new Vector3(350, 50, 0);
            chestUi           = screen.GetComponent <DynamicInterface>();
            chestUi.inventory = inv;
            // chestUi.UpdateSlots();

            // inventory = collision.gameObject.GetComponent<Player>().inventory;
        }
    }
예제 #7
0
        public void TestDynamicInterfaceAgainstClass()
        {
            var di = new DynamicInterface();

            var idyn = di.Create <IDynTest>(typeof(DynInst));

            idyn.One();
            Assert.True(idyn.Two());
            Assert.Equal("Three", idyn.Three());
            Assert.Equal("Four4", idyn.Four(4));
            Assert.Equal("Four5hi", idyn.Five(5, "hi"));

            Assert.True(idyn.IsMethodImplemented("One"));
            Assert.True(idyn.IsMethodImplemented("Two"));
            Assert.True(idyn.IsMethodImplemented("Three"));
            Assert.True(idyn.IsMethodImplemented("Four"));
            Assert.True(idyn.IsMethodImplemented("Five"));
        }
예제 #8
0
        public void TestChaining()
        {
            var di       = new DynamicInterface();
            var instance = di.Create <IDynTest>(
                new {
                One = new Action(() => {
                    Console.WriteLine("Instance1::One");
                }),
            }, new {
                Two = new Func <bool>(() => {
                    Console.WriteLine("Instance1::Two");
                    return(true);
                })
            }
                );


            instance.One();

            // override 1:one
            var instance2 = di.Create <IDynTest>(
                new {
                One = new Action(() => {
                    Console.WriteLine("Instance3::One");
                }),
                Two = new Func <bool>(() => { return(instance.Two()); })
            }
                , instance);

            var instance3 = di.Create <IDynTest>(
                new {
                Four = new Func <int, string>((i) => {
                    Console.WriteLine("Instance3::Four");
                    return("::" + i);
                }),
            }, instance2);


            instance3.One();
            instance3.Two();
            instance3.Three();
            instance3.Four(100);
            instance3.Five(100, "hi");
        }
예제 #9
0
        public void TestDynamicInterfaceAgainstAnonymousObjectsInDifferentOrder()
        {
            using (CaptureConsole) {
                var dynamicInstance = DynamicInterface.DynamicCast <IDynTest>(new {
                    Two = new Func <bool>(() => { return(true); })
                }, new {
                    Four = new Func <int, string>((i) => "::" + i)
                }, new {
                    One = new Action(() => {}),
                });

                Assert.True(dynamicInstance.IsMethodImplemented("One"));
                Assert.True(dynamicInstance.IsMethodImplemented("Two"));
                Assert.False(dynamicInstance.IsMethodImplemented("Three"));
                Assert.True(dynamicInstance.IsMethodImplemented("Four"));
                Assert.False(dynamicInstance.IsMethodImplemented("Five"));

                Assert.True(dynamicInstance.Two());
                Assert.Equal("::4", dynamicInstance.Four(4));
            }
        }
예제 #10
0
        public void TestDynamicInterfaceAgainstAnonymousObjects()
        {
            var di = new DynamicInterface();

            var dynamicInstance = di.Create <IDynTest>(new {
                One = new Action(() => { }),
            }, new {
                Two = new Func <bool>(() => { return(true); })
            }, new {
                Four = new Func <int, string>((i) => "::" + i)
            });

            Assert.True(dynamicInstance.IsMethodImplemented("One"));
            Assert.True(dynamicInstance.IsMethodImplemented("Two"));
            Assert.False(dynamicInstance.IsMethodImplemented("Three"));
            Assert.True(dynamicInstance.IsMethodImplemented("Four"));
            Assert.False(dynamicInstance.IsMethodImplemented("Five"));

            Assert.True(dynamicInstance.Two());
            Assert.Equal("::4", dynamicInstance.Four(4));
        }
예제 #11
0
        public void TestClassImplementation()
        {
            using (CaptureConsole) {
                var dynamicInstance = DynamicInterface.DynamicCast <AbstractDynTest>(new {
                    One = new Action(() => {}),
                }, new {
                    Two = new Func <bool>(() => { return(true); })
                }, new {
                    Four = new Func <int, string>((i) => "::" + i)
                });

                Assert.True(dynamicInstance.IsMethodImplemented("One"));
                Assert.True(dynamicInstance.IsMethodImplemented("Two"));
                Assert.False(dynamicInstance.IsMethodImplemented("Three"));
                Assert.True(dynamicInstance.IsMethodImplemented("Four"));
                Assert.False(dynamicInstance.IsMethodImplemented("Five"));

                dynamicInstance.One();
                dynamicInstance.Two();
                dynamicInstance.Three();
                dynamicInstance.Four(100);
                dynamicInstance.Five(100, "hi");
            }
        }
예제 #12
0
 public void CreateTypeWithBadArguments()
 {
     using (CaptureConsole) {
         Assert.Throws <Exception>(() => { DynamicInterface.Create <IDynTest>(typeof(object), typeof(File)); });
     }
 }
예제 #13
0
 private void Awake()
 {
     inventory = FindObjectOfType <DynamicInterface>();
     equipment = FindObjectOfType <StaticInterface>();
 }
 private void Awake()
 {
     inventory = FindObjectOfType <DynamicInterface>();
     equipment = FindObjectOfType <StaticInterface>();
     text      = GetComponent <TextMeshProUGUI>();
 }