/// <summary> /// Converts a generic collection of <see cref="ValueType"/> /// to a <see cref="string"/> delimited by the value /// of the <paramref name="separator"/> parameter, /// by calling the <see cref="ValueType.ToString()"/> /// method on each item in the source collection, /// and removing any duplicates. /// </summary> /// <param name="collection"> /// A generic collection of <see cref="ValueType"/> items. /// </param> /// <param name="separator"> /// A string delimiter to use instead of a comma. /// </param> /// <param name="removeDuplicates"> /// Whether to remove duplicate items in the array returned. /// Parameter is optional, default value is <c>false</c>. /// </param> /// <typeparam name="T"> /// The generic type of <paramref name="collection"/>, /// derived from <see cref="ValueType"/>. /// </typeparam> /// <returns> /// A <paramref name="separator"/>-delimited string. /// </returns> public static string ToDelimitedString <T>( this IEnumerable <T> collection, [NotNull] string separator, bool removeDuplicates = DefaultRemoveDuplicates) where T : struct { Contract.Requires <ArgumentException>(!ConvertStrings.IsNullOrWhiteSpace(separator)); return(collection.ToDelimitedString( null, separator, removeDuplicates)); }
/// <summary> /// Converts a generic collection of <see cref="ValueType"/> /// to a <see cref="string"/> delimited by the value /// of the <paramref name="separator"/> parameter, /// by calling the <paramref name="toStringMethod"/> /// delegate on each item in the source collection, /// and optionally removing any duplicates. /// </summary> /// <param name="collection"> /// A generic collection of <see cref="ValueType"/> items. /// </param> /// <param name="toStringMethod"> /// A delegate function which accepts a <typeparamref name="T"/> /// value and returns a string. Pass this parameter if a custom /// format string is needed. If not specified, uses the default /// <see cref="ValueType.ToString"/> method. /// </param> /// <param name="separator"> /// A string delimiter to use instead of a comma. /// </param> /// <param name="removeDuplicates"> /// Whether to remove duplicate items in the array returned. /// Parameter is optional, default value is <c>false</c>. /// </param> /// <typeparam name="T"> /// The generic type of <paramref name="collection"/>, /// derived from <see cref="ValueType"/>. /// </typeparam> /// <returns> /// A <paramref name="separator"/>-delimited string. /// </returns> public static string ToDelimitedString <T>( this IEnumerable <T> collection, Func <T, string> toStringMethod, [NotNull] string separator, bool removeDuplicates = DefaultRemoveDuplicates) where T : struct { Contract.Requires <ArgumentException>(!ConvertStrings.IsNullOrWhiteSpace(separator)); return(string.Join( separator, collection.ToStringArray(toStringMethod, removeDuplicates))); }