예제 #1
0
        private static void WriteObject(Object obj, Type type, DumpContext ctx)
        {
            if (!ctx.CanUseToStringForType(type))
            {
                ctx.Builder.Append(type.FullName);
                return;
            }
            String text = ToStringSafe(obj);

            String[] lines = text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            if (lines.Length <= 1)
            {
                ctx.Builder.Append(text);
            }
            else
            {
                ctx.Builder.IncreaseIndent();
                foreach (String line in lines)
                {
                    ctx.Builder.EmptyLine().BeginLine(line);
                }
                ctx.Builder.DecreaseIndent();
            }
        }
예제 #2
0
        private static void DumpObject(Object obj, Boolean bNeedTypeName, DumpContext ctx)
        {
            if (obj == null)
            {
                ctx.Builder.Append("<NULL>");
                return;
            }
            Type     type     = obj.GetType();
            TypeCode typeCode = Type.GetTypeCode(type);

            if (typeCode == TypeCode.String)
            {
                WriteObject(obj, type, ctx);
                return;
            }
            if (typeCode != TypeCode.Object)
            {
                ctx.Builder.Append(ToStringSafe(obj));
                return;
            }
            if (ctx.Depth > ctx.Settings.MaxDepth)
            {
                WriteObject(obj, type, ctx);
                return;
            }
            if (ctx.CanUseToStringForType(type))
            {
                var toStringMethod = type.GetMethod(
                    "ToString",
                    BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
                    null,
                    Type.EmptyTypes,
                    null);
                if (toStringMethod != null)
                {
                    WriteObject(obj, type, ctx);
                    return;
                }
            }
            if (typeof(Stream).IsAssignableFrom(type))
            {
                WriteObject(obj, type, ctx);
                return;
            }
            if (bNeedTypeName)
            {
                ctx.Builder.Append("{").Append(type.Name).Append("}: ");
            }
            if (ctx.Depth > 0)
            {
                ctx.Builder.IncreaseIndent();
            }
            ctx.Depth++;
            IEnumerable enumerable;

            if ((enumerable = obj as IEnumerable) != null)
            {
                DumpEnumerable(enumerable, ctx);
            }
            else
            {
                DumpProps(obj, type, ctx);
            }
            ctx.Depth--;
            if (ctx.Depth > 0)
            {
                ctx.Builder.DecreaseIndent();
            }
        }
예제 #3
0
 private static void DumpObject(Object obj, Boolean bNeedTypeName, DumpContext ctx)
 {
     if (obj == null)
     {
         ctx.Builder.Append("<NULL>");
         return;
     }
     Type type = obj.GetType();
     TypeCode typeCode = Type.GetTypeCode(type);
     if (typeCode == TypeCode.String)
     {
         WriteObject(obj, type, ctx);
         return;
     }
     if (typeCode != TypeCode.Object)
     {
         ctx.Builder.Append(ToStringSafe(obj));
         return;
     }
     if (ctx.Depth > ctx.Settings.MaxDepth)
     {
         WriteObject(obj, type, ctx);
         return;
     }
     if (ctx.CanUseToStringForType(type))
     {
         var toStringMethod = type.GetMethod(
             "ToString",
             BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
             null,
             Type.EmptyTypes,
             null);
         if (toStringMethod != null)
         {
             WriteObject(obj, type, ctx);
             return;
         }
     }
     if (typeof (Stream).IsAssignableFrom(type))
     {
         WriteObject(obj, type, ctx);
         return;
     }
     if (bNeedTypeName)
         ctx.Builder.Append("{").Append(type.Name).Append("}: ");
     if (ctx.Depth > 0)
         ctx.Builder.IncreaseIndent();
     ctx.Depth++;
     IEnumerable enumerable;
     if ((enumerable = obj as IEnumerable) != null)
         DumpEnumerable(enumerable, ctx);
     else
         DumpProps(obj, type, ctx);
     ctx.Depth--;
     if (ctx.Depth > 0)
         ctx.Builder.DecreaseIndent();
 }
예제 #4
0
 private static void WriteObject(Object obj, Type type, DumpContext ctx)
 {
     if (!ctx.CanUseToStringForType(type))
     {
         ctx.Builder.Append(type.FullName);
         return;
     }
     String text = ToStringSafe(obj);
     String[] lines = text.Split(new[] {Environment.NewLine}, StringSplitOptions.None);
     if (lines.Length <= 1)
         ctx.Builder.Append(text);
     else
     {
         ctx.Builder.IncreaseIndent();
         foreach (String line in lines)
         {
             ctx.Builder.EmptyLine().BeginLine(line);
         }
         ctx.Builder.DecreaseIndent();
     }
 }