/// <summary> /// Converts a string array into a string. /// </summary> /// <remarks> /// This method converts a string array into a string. /// </remarks> /// <param name="items"> /// The list of strings to be stringified. /// </param> /// <returns> /// The resulting string. /// </returns> private static String Stringify(this String[] items) { if (items != null && items.Length > 0) { return(ArgumentComposer.Stringify(new List <String>(items))); } else { return(String.Empty); } }
/// <summary> /// This method converts the given list of strings into one single string using /// given separator as delimiter. /// </summary> /// <remarks> /// If one of string inside the list does contain whitespaces then this string /// part is surrounded by double quotes. /// </remarks> /// <param name="arguments"> /// The list of string to be combined. /// </param> /// <param name="separator"> /// The separator to be used as delimiter. /// </param> /// <returns> /// A string representing all items of the processed argument list. /// </returns> public static String Combine(this String[] arguments, Char separator) { if (arguments != null) { return(ArgumentComposer.Combine(arguments.ToList(), separator)); } else { return(String.Empty); } }
/// <summary> /// This method is actually a bonus functionality that might be used to convert /// all public read/writable properties of an object into its string representation. /// Such a string representation might perhaps be used for debug purposes. /// </summary> /// <remarks> /// Note that not all possible data types are supported. This applies especially /// to all generic data types. /// </remarks> /// <param name="instance"> /// The object to get a string representation for. /// </param> /// <returns> /// The string representation of given object. /// </returns> public static String Stringify(this Object instance) { String result = String.Empty; if (instance != null) { StringBuilder buffer = new StringBuilder(512); BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.SetProperty; PropertyInfo[] properties = instance.GetType().GetProperties(flags); if (properties != null) { for (Int32 index = 0; index < properties.Length; index++) { PropertyInfo property = properties[index]; Object value = property.GetValue(instance); String output = String.Empty; if (value != null) { if (value.GetType() == typeof(String[])) { output = $"[{ArgumentComposer.Stringify((String[])value)}]"; } else if (value.GetType() == typeof(List <String>)) { output = $"[{ArgumentComposer.Stringify((List<String>)value)}]"; } else { if (value.GetType() == typeof(String)) { output = $"\"{value.ToString()}\""; } else { output = $"{value.ToString()}"; } } } else { output = "<null>"; } if (index < properties.Length - 1) { buffer.Append($"{property.Name}: {output}, "); } else { buffer.Append($"{property.Name}: {output}"); } } } result = buffer.ToString(); } return(result); }
/// <summary> /// This method converts the given list of strings into one single string using /// the default separator as delimiter. /// </summary> /// <remarks> /// If one of string inside the list does contain whitespaces then this string /// part is surrounded by double quotes. /// </remarks> /// <param name="arguments"> /// The list of string to be combined. /// </param> /// <returns> /// A string representing all items of the processed argument list. /// </returns> public static String Combine(this IEnumerable <String> arguments) { return(ArgumentComposer.Combine(arguments, ParameterSeparators.DefaultSeparator)); }