コード例 #1
0
        public void ShouldBeAbleToAddNewMethodOverloadsFromDelegates()
        {
            var                     writtenLines = new List <string>();
            Action <string>         writeLine1   = text => { writtenLines.Add(text); };
            Action <string, string> writeLine2   = (arg1, arg2) => { writtenLines.Add($"{arg1} {arg2}"); };

            dynamic foo = new MetaObject();

            foo.WriteLine = writeLine1;
            foo.WriteLine = writeLine2;
            foo.WriteLine("Hello, World!");
            foo.WriteLine("Hi", "Everyone!");

            Assert.Contains(writtenLines, text => text == "Hello, World!");
            Assert.Contains(writtenLines, text => text == "Hi Everyone!");
        }
コード例 #2
0
        public void ShouldBeAbleToAddNewMethodsFromDelegates()
        {
            var             writtenLines = new List <string>();
            Action <string> writeLine    = text => { writtenLines.Add(text); };

            dynamic foo = new MetaObject();

            foo.WriteLine = writeLine;
            foo.WriteLine("Hello, World!");

            Assert.Single(writtenLines, text => text == "Hello, World!");
        }