Search code examples
c#c#-3.0extension-methods

Suggestions for String and DateTime utility functions library using Extension Methods


I'm writing a library of Extension Methods for String and DateTime utility functions in C#. What useful utility functions for String and DateTime might engineers want to be part of it? With your suggestions I can make it more cohesive and Collective.


Solution

  • public static bool IsNullOrEmpty(this string value){
        return string.IsNullOrEmpty(value);
    }
    public static string Reverse(this string value) {
        if (!string.IsNullOrEmpty(value)) {
            char[] chars = value.ToCharArray();
            Array.Reverse(chars);
            value = new string(chars);
        }
        return value;
    }
    public static string ToTitleCase(this string value) {
        return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(value);
    }
    public static string ToTitleCaseInvariant(this string value) {
        return CultureInfo.InvariantCulture.TextInfo.ToTitleCase(value);
    }
    

    Trivial, but slighty nicer to call.