public void should_alter_tab_depth_with_indent_and_outdent()
        {
            var sb     = new StringBuilder();
            var writer = new IndentableTextWriter(new StringWriter(sb), "\t", "\n");

            writer.Write("a small");
            writer.WriteLine(" test");
            writer.Indent();
            writer.WriteLine("determines\n");
            writer.Outdent();
            writer.Write("if\r");
            writer.Indent();
            writer.WriteLine("this");
            writer.WriteLine("\twill");
            writer.Indent();
            writer.WriteLine("work");

            sb.ToString().Should().Be("a small test\n\tdetermines\n\nif\n\tthis\n\t\twill\n\t\twork\n");
            Console.Out.WriteLine(sb.ToString());
        }
Exemplo n.º 2
0
        private void WriteObjectImpl(ObjectInfo objectInfo)
        {
            //Assumption: the label has already been printed on the line.
            //            if you _output.WriteLine, the value will not appear
            //            on same line as the label

            var objToAppend = objectInfo.Value;

            if (objToAppend == null)
            {
                _output.Write(NullValue);
                return;
            }

            Type typeOfOjbToAppend = objectInfo.Type;

            //Avoid referential loops by not letting an object be dumped as a descendent in the graph
            //TODO: when value types create circular references, this fails
            //		because ReferenceEquals will box the value type and thus never have the same reference
            if (_objStack.Any(o => ReferenceEquals(objToAppend, o)))
            {
                _output.Write("avoid circular loop for this [" + typeOfOjbToAppend.Name + "]: hashcode { " + objToAppend.GetHashCode() + " }");
                return;
            }

            //Avoid StackOverflow caused by recursive value types like Linq2Sql or ConfigurationException.Errors
            if (_currentDepth >= _config.MaxDepth)
            {
                _output.Write("Maximum recursion depth (" + _config.MaxDepth + ") reached");
                return;
            }


            //*** continue recursive printing of the object

            _objStack.Push(objToAppend);

            var stringToAppend = objToAppend as string;

            if (stringToAppend != null)
            {
                //in case the string contains line returns, the next line will be indented from the member name
                _output.Indent();
                _output.Write(stringToAppend);
                _output.Outdent();
            }
            else
            {
                object            singleValue;
                List <ObjectInfo> properties;

                if (TryGetSingleValue(objectInfo, out singleValue, out properties))
                {
                    _output.Write(singleValue ?? NullValue);
                }
                else
                {
                    _output.Write("[" + typeOfOjbToAppend.Name + "]: hashcode { " + objToAppend.GetHashCode() + " }");
                    if (_config.IncludeLogging)
                    {
                        var inspectorName = objectInfo.Inspector == null
                                                                    ? NullValue
                                                                    : objectInfo.Inspector.GetType().Name;
                        _output.Write(" - Inspector { " + inspectorName + " } ");
                    }
                    _objectInfosPrinter.Write(properties);
                }
            }

            //we are done printing the descendents of this object.
            //free it to be printed in another section.
            _objStack.Pop();
        }
Exemplo n.º 3
0
 private void StartChildWrapper()
 {
     _output.WriteLine();
     _output.WriteLine("{");
     _output.Indent();
 }