Example #1
0
        public static string GetObjectText(this ILogger lg, object obj)
        {
            StringWriter stringWriter = new StringWriter();

            ObjectDumper2.Dump(obj, "", (TextWriter)stringWriter, true);
            return(stringWriter.ToString());
        }
Example #2
0
        public static void Dump(object value, string name, TextWriter writer, bool CompactMode)
        {
            //if (ObjectDumper2.IsNullOrWhiteSpace(name))
            //    throw new ArgumentNullException("name");
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            ObjectIDGenerator idGenerator = new ObjectIDGenerator();

            ObjectDumper2.InternalDump(0, name, value, writer, idGenerator, true, CompactMode);
        }
Example #3
0
 private static void WriteObject(int indentationLevel, object value, TextWriter writer, ObjectIDGenerator idGenerator, bool CompactMode, string str1, Type type)
 {
     PropertyInfo[] propertyInfoArray = Enumerable.ToArray <PropertyInfo>(Enumerable.Where <PropertyInfo>((IEnumerable <PropertyInfo>)type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic), (Func <PropertyInfo, bool>)(property => property.GetIndexParameters().Length == 0 && property.CanRead)));
     FieldInfo[]    fieldInfoArray    = Enumerable.ToArray <FieldInfo>((IEnumerable <FieldInfo>)type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic));
     if (propertyInfoArray.Length == 0 && fieldInfoArray.Length == 0)
     {
         return;
     }
     writer.WriteLine("{0}{{", str1);
     if (propertyInfoArray.Length > 0)
     {
         writer.WriteLine("{0}   properties {{", str1);
         foreach (PropertyInfo propertyInfo in propertyInfoArray)
         {
             try
             {
                 object obj = propertyInfo.GetValue(value, (object[])null);
                 ObjectDumper2.InternalDump(indentationLevel + 2, propertyInfo.Name, obj, writer, idGenerator, true, CompactMode);
             }
             catch (TargetInvocationException ex)
             {
                 ObjectDumper2.InternalDump(indentationLevel + 2, propertyInfo.Name, (object)ex, writer, idGenerator, false, CompactMode);
             }
             catch (ArgumentException ex)
             {
                 ObjectDumper2.InternalDump(indentationLevel + 2, propertyInfo.Name, (object)ex, writer, idGenerator, false, CompactMode);
             }
             catch (RemotingException ex)
             {
                 ObjectDumper2.InternalDump(indentationLevel + 2, propertyInfo.Name, (object)ex, writer, idGenerator, false, CompactMode);
             }
         }
         writer.WriteLine("{0}   }}", str1);
     }
     if (fieldInfoArray.Length > 0 && !CompactMode)
     {
         writer.WriteLine("{0}   fields {{", str1);
         foreach (FieldInfo fieldInfo in fieldInfoArray)
         {
             try
             {
                 object obj = fieldInfo.GetValue(value);
                 ObjectDumper2.InternalDump(indentationLevel + 2, fieldInfo.Name, obj, writer, idGenerator, true, CompactMode);
             }
             catch (TargetInvocationException ex)
             {
                 ObjectDumper2.InternalDump(indentationLevel + 2, fieldInfo.Name, (object)ex, writer, idGenerator, false, CompactMode);
             }
         }
         writer.WriteLine("{0}   }}", str1);
     }
 }