private bool InspectDeepness(ClassMember cm, TextWriter tw, int depth) { if (depth >= Settings.MaxDepth) { _formatter.WriteText(string.Format("{0}{1}{2}", "{", cm.GetClassMemberType().ToString(), "}"), 0, tw); return(true); } return(false); }
internal IEnumerable <TraverseNode> GetChildren(ObjectDumperSettings settings) { List <TraverseNode> children = new List <TraverseNode>(); if (Item == null || Item is ValueType || Item is string) { return(children); } if (Item is IEnumerable) { return(children); } List <MemberInfo> members = Item.GetType().GetMembers(settings.BindingFlags).ToList(); foreach (MemberInfo member in members) { Type type = member.DeclaringType; if (type.FullName.Equals($"System.{type.Name}", StringComparison.Ordinal)) { continue; } if (type.FullName.Equals($"System.Reflection.{type.Name}", StringComparison.Ordinal)) { continue; } if (IgnoreCompilerGeneratedMember(member, settings)) { continue; } ClassMember cm = new ClassMember(member); if (cm.IsValid()) { object value = cm.GetValue(Item); children.Add(new TraverseNode(cm.GetName(), cm.GetClassMemberType().FullName, value, this, Level + 1)); } } return(children.OrderBy(x => x.Name)); }
private void ObjectDump(object obj, TextWriter tw, int currentDepth) { Type type = obj.GetType(); if (type.FullName.Equals($"System.{type.Name}", StringComparison.Ordinal)) { return; } if (type.FullName.Equals($"System.Reflection.{type.Name}", StringComparison.Ordinal)) { return; } int textTabs = currentDepth + 1; _formatter.NewLine(tw); _formatter.WriteText("{", currentDepth, tw); _formatter.NewLine(tw); if (obj == null || obj is ValueType || obj is string) { _formatter.WriteValue(obj, tw); } else { MemberInfo[] members = type.GetMembers(Settings.BindingFlags); for (int i = 0; i < members.Length; i++) { MemberInfo member = members[i]; if (IgnoreCompilerGeneratedMember(member)) { continue; } ClassMember cm = new ClassMember(member); if (cm.IsValid()) { object value = cm.GetValue(obj); if (cm.IsValueType() || cm.IsString()) { _formatter.WriteName(cm.GetNames(), textTabs, tw, Settings.WriteElementType); _formatter.WriteValue(value, tw); } else if (cm.IsEnumerable()) { _formatter.WriteName(cm.GetNames(), textTabs, tw, Settings.WriteElementType); if (!InspectDeepness(cm, tw, currentDepth)) { IEnumerable enumerable = value as IEnumerable; if (enumerable == null) { _formatter.WriteValue(enumerable, tw); } else { foreach (object item in enumerable) { Dump(item, tw, currentDepth + 1); } } } } else { _formatter.WriteName(cm.GetNames(), textTabs, tw, Settings.WriteElementType); if (value == null) { _formatter.WriteValue(value, tw); } else { if (!InspectDeepness(cm, tw, currentDepth)) { Dump(value, tw, currentDepth + 1); } } } if (i + 1 < members.Length) { _formatter.NewLine(tw); } } } } _formatter.NewLine(tw); _formatter.WriteText("}", currentDepth, tw); }