Skip to content

Commit

Permalink
Minor fixes and new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
safalin1 committed Aug 25, 2019
1 parent 511247b commit 2738d46
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Chiaki/BinarySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace Chiaki
{
/// <summary>
/// Provides a serializer which can write an instance of an object to binary.
/// </summary>
public static class BinarySerializer
{
/// <summary>
Expand Down
19 changes: 19 additions & 0 deletions Chiaki/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,24 @@ public static IEnumerable<TSource> WhereIf<TSource>(this IEnumerable<TSource> so
? source.Where(predicate)
: source;
}

/// <summary>
/// Returns true if all items in the other enumerable exist in the source enumerable.
/// </summary>
public static bool ContainsAll<TSource>(this IEnumerable<TSource> source, IEnumerable<TSource> other)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (other == null) throw new ArgumentNullException(nameof(other));

return !other.Except(source).Any();
}

/// <summary>
/// Returns true if the source enumerable contains any of the items in the other enumerable.
/// </summary>
public static bool ContainsAny<TSource>(this IEnumerable<TSource> source, IEnumerable<TSource> other)
{
return other.Any(source.Contains);
}
}
}
14 changes: 12 additions & 2 deletions Chiaki/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ public static string RemoveNewLines(this string input)
.Replace("\n", string.Empty);
}

/// <summary>
/// Converts all new lines characters "\n" to html break tags.
/// </summary>
public static string ConvertNewLinesToHtmlTags(this string input)
{
return input
.Replace("\r", string.Empty)
.Replace("\n", "<br />");
}

/// <summary>
/// Converts a string to hexadecimal format.
/// </summary>
Expand Down Expand Up @@ -209,15 +219,15 @@ public static string TruncateTo(this string input, int maxLength, string suffix
/// <summary>
/// Replaces one or more format items in a specified string with the string representation of a specified object.
/// </summary>
public static string Format(this string input, object arg0)
public static string Formatted(this string input, object arg0)
{
return string.Format(input, arg0);
}

/// <summary>
/// Replaces one or more format items in a specified string with the string representation of a specified object.
/// </summary>
public static string Format(this string input, params object[] args)
public static string Formatted(this string input, params object[] args)
{
return string.Format(input, args);
}
Expand Down

0 comments on commit 2738d46

Please sign in to comment.