예제 #1
0
        private void ResultsReceived(Object data)
        {
            var writer = new StringWriter();
            var dumper = new ObjectTextDumper(writer);

            dumper.Dump(data);

            Paragraph paragraph = new Paragraph();
            Bold      recv      = new Bold();
            var       converter = new System.Windows.Media.BrushConverter();

            recv.Foreground = (Brush)converter.ConvertFromString("#FF8ACCCF");
            recv.FontSize   = 14.0;
            recv.Inlines.Add("Event Received :" + Environment.NewLine);
            paragraph.Inlines.Add(recv);

            Span text = new Span();

            text.Foreground = (Brush)converter.ConvertFromString("#FFDFDFBF");
            text.Inlines.Add(writer.GetStringBuilder().ToString());
            paragraph.Inlines.Add(text);

            View.console.Document.Blocks.Add(paragraph);
            View.scroller.ScrollToBottom();
        }
예제 #2
0
파일: Program.cs 프로젝트: cnarasimhagit/vm
        static void Main()
        {
            int anInt    = 5;
            var anObject = new MyClass
            {
                BoolProperty = true,
                IntProperty  = 3,
                GuidProperty = Guid.Empty,
            };

#if false
            // Initial fully spelled-out version:
            using (var writer = new StringWriter())
            {
                var dumper = new ObjectTextDumper(writer);

                // dump a primitive value:
                dumper.Dump(anInt);
                // dump complex value:
                dumper.Dump(anObject);
                Console.WriteLine(writer.GetStringBuilder().ToString());
            }
#elif false
            // Alternative #1. Use the DumpText() extension method:
            using (var writer = new StringWriter())
            {
                anInt.DumpText(writer);
                anObject.DumpText(writer);
                Console.WriteLine(writer.GetStringBuilder().ToString());
            }
#elif true
            // Alternative #2. Use the DumpString() extension method:
            Console.WriteLine(anInt.DumpString());
            Console.WriteLine(anObject.DumpString());
#elif false
            // Alternative #3. Override MyClass.ToString()
            Console.WriteLine(anInt.DumpString());
            Console.WriteLine(anObject.ToString());
#endif

            Console.Write("Press any key to finish...");
            Console.ReadKey(true);
        }
예제 #3
0
        public static object DumpText(
            this object value,
            TextWriter writer,
            int indentLevel             = 0,
            Type dumpMetadata           = null,
            DumpAttribute dumpAttribute = null)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            try
            {
                using (var dumper = new ObjectTextDumper(writer))
                    dumper.Dump(value, dumpMetadata, dumpAttribute, indentLevel);
            }
            catch (Exception x)
            {
                writer.WriteLine($"\n\nATTENTION:\nThe TextDumper threw an exception:\n{x.ToString()}");
            }

            return(value);
        }