Skip to content

Instantly share code, notes, and snippets.

@goodwill
Created May 18, 2009 03:52
Show Gist options
  • Save goodwill/113306 to your computer and use it in GitHub Desktop.
Save goodwill/113306 to your computer and use it in GitHub Desktop.
public static class StringUtil
{
public static string NullDefault(this string value, string valueIfNull)
{
if (string.IsNullOrEmpty(value))
return valueIfNull;
else
return value;
}
public static bool IsNullOrDefault(this string value, string valueIfNull, bool ignoreCase)
{
StringComparison compareParam=StringComparison.InvariantCulture;
if (ignoreCase)
compareParam=StringComparison.InvariantCultureIgnoreCase;
return String.Equals(NullDefault(value, valueIfNull), valueIfNull, compareParam);
}
public static bool IsNullOrDefault(this string value, string valueIfNull)
{
return IsNullOrDefault(value, valueIfNull, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment