Skip to content

Commit

Permalink
Added more string extentions
Browse files Browse the repository at this point in the history
  • Loading branch information
Teodor92 committed Mar 4, 2016
1 parent 720778b commit 5ec11d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Source/MoreDotNet/Extentions/EnumerableExtentions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Collections.Generic;
using System.Linq;

public static class EnumerableExtentions
{
Expand All @@ -12,5 +13,10 @@ public static void ForEach<T>(this IEnumerable<T> collection, Action<T> mapFunct
mapFunction(item);
}
}

public static IEnumerable<T> EmptyIfNull<T>(this IEnumerable<T> pSeq)
{
return pSeq ?? Enumerable.Empty<T>();
}
}
}
8 changes: 8 additions & 0 deletions Source/MoreDotNet/Extentions/GenericExtentions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ public static bool IsBetween<T>(this T actual, T lowerBound, T upperBound) where
{
return actual.CompareTo(lowerBound) >= 0 && actual.CompareTo(upperBound) < 0;
}

public static void ThrowIfArgumentIsNull<T>(this T obj, string parameterName) where T : class
{
if (obj == null)
{
throw new ArgumentNullException("parameterName", parameterName + " not allowed to be null");
}
}
}
}
17 changes: 17 additions & 0 deletions Source/MoreDotNet/Extentions/StringExtentions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace MoreDotNet.Extentions
{
using System.Text.RegularExpressions;
using System.Threading;

public static class StringExtentions
Expand All @@ -17,5 +18,21 @@ public static string ToTitleCase(this string inputText)
// TextInfo.ToTitleCase only operates on the string if is all lower case, otherwise it returns the string unchanged.
return textInfo.ToTitleCase(inputText.ToLower());
}

public static string ToWords(this string camelCaseWord)
{
// if the word is all upper, just return it
if (!Regex.IsMatch(camelCaseWord, "[a-z]"))
{
return camelCaseWord;
}

return string.Join(" ", Regex.Split(camelCaseWord, @"(?<!^)(?=[A-Z])"));
}

public static string Capitalize(this string word)
{
return word[0].ToString().ToUpper() + word.Substring(1);
}
}
}

0 comments on commit 5ec11d1

Please # to comment.