Created
March 27, 2014 11:14
-
-
Save baba-s/9805288 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <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