WriteObject() private method

private WriteObject ( object element ) : void
element object
return void
Example #1
0
        /// <summary>
        /// Writes the specified element.
        /// </summary>
        /// <param name="prefix">The prefix to print.</param>
        /// <param name="element">The element to dump.</param>
        /// <param name="depth">The iteration level.</param>
        /// <param name="maxcount">The maximum count of dumps.</param>
        /// <param name="log">The output logger.</param>
        public static void Write(string prefix, object element, int depth, int maxcount, TextWriter log)
        {
            ObjectDumper dumper = new ObjectDumper(depth, maxcount);

            dumper.writer = log;
            // string prefix = null;
            if (element != null)
            {
                dumper.Write("[" + element.GetType().Name + "]" + log.NewLine);
                //prefix = "[" + element.GetType().Name + "]";
            }
            dumper.WriteObject(prefix, element);
        }
Example #2
0
        /// <summary>
        /// Dumps the specified object.
        /// </summary>
        /// <typeparam name="T">Type of the object</typeparam>
        /// <param name="o">The object to dump.</param>
        /// <param name="prefix">The prefix to print on the left side.</param>
        /// <param name="description">The description text.</param>
        /// <param name="maximumDepth">The maximum dump regression depth.</param>
        /// <param name="maxcount">The maximum count of dumps.</param>
        /// <returns>
        /// The untouched object for fluent usage of <c>Dump</c>.
        /// </returns>
        public static T Dump <T>(this T o, string prefix, string description, int maximumDepth, int maxcount)
        {
            if (maximumDepth < 0)
            {
                maximumDepth = 0;
            }
            if (maximumDepth > 20)
            {
                maximumDepth = 20;
            }

            if (!string.IsNullOrEmpty(description))
            {
                maximumDepth++;
            }

            if (maxcount < 0)
            {
                maxcount = 0;
            }

            Expression expr = null;
            //TextWriter lambdaFormatter = new StringWriter();
            TextWriter lambdaFormatter = Server.Default.LambdaFormatter;

            if (lambdaFormatter != null)
            {
                if (o is IQueryable)
                {
                    expr = ((IQueryable)o).Expression;
                }
                else if (o is Expression)
                {
                    expr = /*(Expression)*/ o as Expression;
                    //expr = (Expression) (object)o;
                    // throw new NotImplementedException("Dump: o is Expression");
                }
            }
            string content = "";

            if (expr != null)
            {
                //throw new NotImplementedException("Dump: o is Expression");
                try
                {
                    ExpressionToken token = ExpressionToken.Visit(expr);
                    if (token != null)
                    {
                        content = token.ToString();
                    }
                }
                catch (Exception exception)
                {
                    Server.Default.LambdaFormatter.Write("Dump ExpressionToken Visit \r\n" + exception.ToString());
                }
            }
            //XhtmlWriter currentResultsWriter = Server.CurrentResultsWriter;
            var  currentResultsWriter = new ObjectDumper(maximumDepth, maxcount, lambdaFormatter);
            bool flag = o is Type;

            if (flag)
            {
                //ObjectNode.ExpandTypes = true;
            }
            try
            {
                TextWriter writer3;
                if (!string.IsNullOrEmpty(description))
                {
                    if (content.Length > 0)
                    {
                        lock ((writer3 = lambdaFormatter))
                        {
                            lambdaFormatter.WriteLine(new HeadingPresenter(description, content));
                        }
                    }
                    HeadingPresenter presenter = new HeadingPresenter(description, o);
                    if (currentResultsWriter != null)
                    {
                        //currentResultsWriter.WriteDepth(presenter, maximumDepth);
                        //ObjectDumper.Write(o, maximumDepth.GetValueOrDefault(), lambdaFormatter);
                        //currentResultsWriter.Write("[" + o.GetType().Name + "]");
                        //currentResultsWriter.Writer = lambdaFormatter;
                        //currentResultsWriter.WriteObject(null, o);
                        currentResultsWriter.WriteObject(presenter);
                        //Text = lambdaFormatter.ToString();
                        return(o);
                    }
                    Console.Write(presenter);
                    return(o);
                }
                if (content.Length > 0)
                {
                    lock ((writer3 = lambdaFormatter))
                    {
                        lambdaFormatter.WriteLine(content + "\r\n");
                    }
                }
                if (currentResultsWriter != null)
                {
                    //currentResultsWriter.WriteLineDepth(o, maximumDepth);
                    currentResultsWriter.WriteObject(o);
                    //Text = lambdaFormatter.ToString();
                    return(o);
                }
                //ObjectDumper.Write(o);
                Console.WriteLine(o);
            }
            finally
            {
                if (flag)
                {
                    //ObjectNode.ExpandTypes = false;
                }
            }
            return(o);
        }