示例#1
0
        public static void Write(this ColoredMessage cm, ConsoleColor?color, string msg)
        {
            if (color != null)
            {
                cm.Parts.Add(new SetColorMessagePart(color.Value));
            }

            cm.Parts.Add(new WriteMessagePart(msg));

            if (color != null)
            {
                cm.Parts.Add(new ResetColorMessagePart());
            }

            /*
             * if (cm != null)
             * {
             *      cm.Append(msg);
             * }
             * else
             * {
             *      if (color == null)
             *      {
             *              Console.Write(msg);
             *      }
             *      else
             *      {
             *              using (Color(color.Value))
             *              {
             *                      Console.Write(msg);
             *              }
             *      }
             * }
             */
        }
示例#2
0
        public static void ToConsole(this ColoredMessage cm)
        {
            var consoleVisitor = new ConsoleMessagePartVisitor();

            foreach (var part in cm.Parts)
            {
                part.Accept(consoleVisitor);
            }
        }
示例#3
0
 public static void Write(this ColoredMessage cm, string msg)
 {
     Write(cm, null, msg);
 }