Пример #1
0
        public void MarcoTest()
        {
            var a = 1;
            var b = 2;
            var actual = 0;
            var expected = 5;

            var cmdA = new Command((parameters) =>
            {
                a++;
            });

            var cmdB = new Command((parameters) =>
            {
                b++;
            });

            var cmdC = new Command((parameters) =>
            {
                actual = a + b;
            });

            /// Another way to execute dynamic command: 
            /// var maco=new Macro();
            /// macro.Add(() => { a++; }, () => { b++; }, () => { actual = a + b; });

            var macro = new Macro(cmdA, cmdB, cmdC);
            macro.Call();

            Assert.AreEqual(expected, actual);
        }
Пример #2
0
 /// <summary>
 /// Add commands and group into a macro by name.
 /// </summary>
 /// <param name="commandName">The command group name.</param>
 /// <param name="commands">The commands add to the naming macro</param>
 public void Add(string commandName, params ICommand[] commands)
 {
     if (this.CommandSet[commandName] != null)
     {
         this.CommandSet[commandName].Add(commands);
     }
     else
     {
         var macro = new Macro();
         macro.Add(commands);
         this.CommandSet.Add(commandName, macro);
     }
 }