private static void AddLineOrFragment(FormattedObjectGraph formattedGraph, int startCount, string fragment) { if (formattedGraph.LineCount > (startCount + 1)) { formattedGraph.AddLine(fragment); } else { formattedGraph.AddFragment(fragment); } }
public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild) { var exception = (AggregateException)value; if (exception.InnerExceptions.Count == 1) { formattedGraph.AddFragment("(aggregated) "); formatChild("inner", exception.InnerException, formattedGraph); } else { formattedGraph.AddLine(Invariant($"{exception.InnerExceptions.Count} (aggregated) exceptions:")); foreach (Exception innerException in exception.InnerExceptions) { formattedGraph.AddLine(string.Empty); formatChild("InnerException", innerException, formattedGraph); } } }
private void WriteTypeAndMemberValues(object obj, FormattedObjectGraph formattedGraph, FormatChild formatChild) { Type type = obj.GetType(); formattedGraph.AddLine(TypeDisplayName(type)); formattedGraph.AddLine("{"); MemberInfo[] members = GetMembers(type); using var iterator = new Iterator <MemberInfo>(members.OrderBy(mi => mi.Name)); while (iterator.MoveNext()) { WriteMemberValueTextFor(obj, iterator.Current, formattedGraph, formatChild); if (!iterator.IsLast) { formattedGraph.AddFragment(", "); } } formattedGraph.AddFragmentOnNewLine("}"); }
public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild) { var exception = (Exception)value; formattedGraph.AddFragment(Invariant($"{exception.GetType().FullName} with message \"{exception.Message}\"")); if (exception.StackTrace is not null) { foreach (string line in exception.StackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.None)) { formattedGraph.AddLine(" " + line); } } }
public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild) { if (value.GetType() == typeof(object)) { formattedGraph.AddFragment($"System.Object (HashCode={value.GetHashCode()})"); return; } if (HasDefaultToStringImplementation(value)) { WriteTypeAndMemberValues(value, formattedGraph, formatChild); } else { if (context.UseLineBreaks) { formattedGraph.AddLine(value.ToString()); } else { formattedGraph.AddFragment(value.ToString()); } } }