/// <summary> /// Iterates and displays the entities in the entity collection. /// </summary> /// <param name="collection">The collection.</param> /// <param name="info">Optional arguments.</param> public static string ToStringDebug(this EntityCollection collection, StringDebugInfo info = null) { info = info ?? StringDebugInfo.Default; if (collection == null) { return(info.Indent + "null"); } var values = collection.Entities.Select(r => r.ToStringAttributes(info.IncreaseIndent()).TrimStart()); if (string.IsNullOrWhiteSpace(collection.EntityName)) { return(Wrap("[", values, "]", info, string.Empty)); } var prefix = info.SingleLine ? string.Empty : Environment.NewLine + info.Indent; var start = $"{{{prefix}{collection.EntityName}:{prefix}["; var end = info.SingleLine ? "]}" : $"]{Environment.NewLine + info.Indent}}}"; return(Wrap(start, collection.Entities.Select(r => r.ToStringAttributes(info)), end, info, string.Empty)); }
/// <summary> /// Iterates and displays the values of the dictionary. /// </summary> /// <param name="dict">The dictionary.</param> /// <param name="info">Optional arguments.</param> public static string ToStringDebug(this Dictionary <string, string> dict, StringDebugInfo info = null) { return(Wrap("{", dict.Select(e => $@"{e.Key}: ""{e.Value}"""), "}", info)); }
/// <summary> /// Returns a StringDebugInfo with no tabs. /// </summary> /// <returns></returns> public StringDebugInfo WithNoTab() { if (this.TabWidth == 0) { return(this); } return(NoTab ?? (NoTab = new StringDebugInfo(this, tabWidth: 0))); }
/// <summary> /// Increases the number of Tabs to increase the Current indent /// </summary> /// <param name="tabs"></param> /// <returns></returns> public StringDebugInfo IncreaseIndent(int tabs = 1) { if (!IncreasedIndents.TryGetValue(tabs, out var indent)) { indent = new StringDebugInfo(this, IndentSpaces + TabWidth * tabs); IncreasedIndents[tabs] = indent; } return(indent); }
private StringDebugInfo(StringDebugInfo toCopy, int?indentSpaces = null, int?tabWidth = null, bool?singleLine = null) { IndentSpaces = indentSpaces ?? toCopy.IndentSpaces; TabWidth = tabWidth ?? toCopy.TabWidth; SingleLine = singleLine ?? toCopy.SingleLine; Indent = ToStringDebugExtensions.GenerateNonBreakingSpace(IndentSpaces); Tab = ToStringDebugExtensions.GenerateNonBreakingSpace(TabWidth); IncreasedIndents = new Dictionary <int, StringDebugInfo>(); }
/// <summary> /// Iterates and displays the attributes listed in the entity's Attributes collection. /// </summary> /// <param name="entity">The entity.</param> /// <param name="info">Optional arguments.</param> public static string ToStringAttributes(this Entity entity, StringDebugInfo info = null) { info = info ?? StringDebugInfo.Default; if (entity == null) { return(info.Indent + "null"); } return(Wrap("{", entity.Attributes.ToStringDebug(info), "}", info)); }
/// <summary> /// Iterates and displays the values in the IEnumerable. /// </summary> /// <param name="collection">The images.</param> /// <param name="info">Optional arguments.</param> public static string ToStringDebug(this IEnumerable collection, StringDebugInfo info = null) { info = info ?? StringDebugInfo.Default; var prefix = info.SingleLine ? string.Empty : Environment.NewLine + info.Indent + info.Tab; var start = $"{{{prefix}\"{collection.GetType().Name}\": ["; var end = info.SingleLine ? "]}" : $"]{Environment.NewLine + info.Indent}}}"; return(Wrap(start, from object item in collection select ObjectToStringDebug(item, info), end, info.IncreaseIndent())); }
/// <summary> /// Iterates and displays the attributes listed in the entity's Attributes collection as well as the Id and LogicalName. /// </summary> /// <param name="entity">The entity.</param> /// <param name="info">Optional arguments.</param> public static string ToStringDebug(this Entity entity, StringDebugInfo info = null) { info = info ?? StringDebugInfo.Default; if (entity == null) { return(info.Indent + "null"); } return(Wrap("{", new[] { "Id: \"" + entity.Id + "\"", "LogicalName: \"" + entity.LogicalName + "\"" }.Concat( entity.Attributes.ToStringDebug(info) ), "}", info)); }
private static string Wrap(string start, IEnumerable <string> middle, string end, StringDebugInfo info, string initialIndent = null, string middleJoinSeparator = ",") { initialIndent = initialIndent ?? info.Indent; if (info.SingleLine) { return(initialIndent + start + string.Join(middleJoinSeparator, middle) + end); } var tab = Environment.NewLine + info.Indent + info.Tab; var joinedMiddle = string.Join(middleJoinSeparator + tab, middle); if (string.IsNullOrWhiteSpace(joinedMiddle)) { return(initialIndent + start + end); } return(initialIndent + start + tab + joinedMiddle + Environment.NewLine + info.Indent + end); }
private static string ObjectToStringDebug(object obj, StringDebugInfo info) { string value; switch (obj) { case null: value = "null"; break; case Entity entity: value = entity.ToStringAttributes(info); break; case EntityReference entityRef: value = entityRef.ToStringDebug(); break; case EntityCollection entities: value = entities.ToStringDebug(info); break; case EntityReferenceCollection entityRefCollection: value = entityRefCollection.ToStringDebug(info); break; case Dictionary <string, string> dict: value = dict.ToStringDebug(info); break; case byte[] imageArray: value = imageArray.ToStringDebug(); break; case IEnumerable enumerable when !(enumerable is string): value = enumerable.ToStringDebug(info); break; case OptionSetValue optionSet: value = optionSet.Value.ToString(CultureInfo.InvariantCulture); break; case Money money: value = money.Value.ToString(CultureInfo.InvariantCulture); break; case bool yesNo: value = yesNo ? "true" : "false"; break; default: value = obj.IsNumeric() ? obj.ToString() : $"\"{obj}\""; break; } return(value); }
/// <summary> /// Iterates and displays the parameters in the parameter collection. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="name">The name.</param> /// <param name="info">Optional arguments.</param> public static string ToStringDebug(this ParameterCollection parameters, string name, StringDebugInfo info = null) { info = info ?? StringDebugInfo.Default; if (parameters == null) { return(info.Indent + name + ": null"); } if (parameters.Count <= 0) { return(info.Indent + name + ": {}"); } var allEntities = parameters.Values.All(a => a is Entity); return(Wrap(info.Indent + name + ": {", parameters.ToStringDebug(allEntities ? info : info.IncreaseIndent()), "}", allEntities ? info.WithNoTab() : info, string.Empty)); }
private static IEnumerable <string> ToStringDebug(this DataCollection <string, object> items, StringDebugInfo info) { foreach (var item in items.OrderBy(kvp => kvp.Key)) { yield return(item.Key + ": " + ObjectToStringDebug(item.Value, info).TrimStart()); } }
/// <summary> /// Iterates and displays the entity references in the entity reference collection. /// </summary> /// <param name="collection">The collection.</param> /// <param name="info">Optional arguments.</param> public static string ToStringDebug(this EntityReferenceCollection collection, StringDebugInfo info = null) { if (collection == null) { return("null"); } return(Wrap("[", collection.Select(r => r.ToStringDebug()), "]", info)); }
/// <summary> /// Iterates and displays the entity images in the entity image collection. /// </summary> /// <param name="images">The images.</param> /// <param name="name">The name.</param> /// <param name="info">Optional arguments.</param> public static string ToStringDebug(this EntityImageCollection images, string name, StringDebugInfo info = null) { info = info ?? StringDebugInfo.Default; if (images == null) { return(info.Indent + name + ": null"); } if (images.Count == 1) { var kvp = images.First(); var id = kvp.Value?.Id == Guid.Empty ? string.Empty : "_" + kvp.Value?.LogicalName + "_" + kvp.Value?.Id.ToString("N"); return(info.Indent + name + id + ": " + images.Values.First().ToStringAttributes(info).TrimStart()); } return(Wrap(name + ": {", images.Select(v => v.Key + ": " + v.Value.ToStringDebug(info).TrimStart()), "}", info.WithNoTab(), string.Empty)); }