public static IDisplayActual Create(object value, int depth = 0, ObjectIDGenerator graph = null) { if (value is null) { return(Null); } if (value is string stringValue) { if (stringValue.Length == 0) { return(EmptyString); } return(new StringDisplayActual(stringValue, depth > 0)); } if (value is Type typeValue) { return(new BasicDisplayActual(TextUtility.ConvertToSimpleTypeName(typeValue), typeof(Type))); } if (value is Exception exceptionValue) { return(Exception(exceptionValue)); } if (value is StringComparer) { return(new BasicDisplayActual(GetStringComparerText(value), value.GetType())); } if (depth > 3) { return(Ellipsis); } if (graph == null) { graph = new ObjectIDGenerator(); } graph.GetId(value, out bool first); if (!first) { return(Ellipsis); } if (value is IDisplayActual da) { return(da); } if (value is IEnumerable enumerableValue) { return(new EnumerableDisplayActual(enumerableValue, depth + 1)); } if (HasToStringOverride(value.GetType())) { return(new BasicDisplayActual(value.ToString(), value.GetType())); } return(new DefaultDisplayActual(value, depth, graph)); }
public string Format(DisplayActualOptions options) { string formatString = options.ShowType() ? "{0} {{ {1} }}" : "{{ {1} }}"; // On recursion, no need to display types var recursionOptions = options & ~DisplayActualOptions.ShowType; return(string.Format( formatString, TextUtility.ConvertToSimpleTypeName(_type), string.Join(", ", _values.Select(v => v.Format(recursionOptions))) )); }
public string Format(DisplayActualOptions options) { var w = Text; if (options.ShowWhitespace()) { w = TextUtility.ShowWhitespace(w); } if (options.ShowType()) { var type = TextUtility.ConvertToSimpleTypeName(Type); w += $" ({type})"; } return(w); }