Skip to content

Instantly share code, notes, and snippets.

@baba-s
Created March 27, 2014 11:14
Show Gist options
  • Select an option

  • Save baba-s/9805288 to your computer and use it in GitHub Desktop.

Select an option

Save baba-s/9805288 to your computer and use it in GitHub Desktop.
/// <summary>
/// string型の拡張メソッドを管理するクラス
/// </summary>
public static partial class StringExtensions
{
/// <summary>
/// 文字列が空の場合はstring.Emptyを返します
/// </summary>
/// <param name="source">空かどうかを確認する文字列</param>
/// <returns>sourceが空の場合はstring.Empty。それ以外の場合はsource</returns>
public static string DefaultIfEmpty(this string source)
{
return string.IsNullOrEmpty(source) ? string.Empty : source;
}
/// <summary>
/// 文字列が空の場合はdefaultValueを返します
/// </summary>
/// <param name="source">空かどうかを確認する文字列</param>
/// <param name="defaultValue">sourceが空の場合に返す文字列</param>
/// <returns>sourceが空の場合はdefaultValue。それ以外の場合はsource</returns>
public static string DefaultIfEmpty(this string source, string defaultValue)
{
return string.IsNullOrEmpty(source) ? defaultValue : source;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment