Last active
December 14, 2015 07:08
-
-
Save shibayan/5047907 to your computer and use it in GitHub Desktop.
This file contains 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
やりたいこと: | |
・object -> IList<object> への変換 | |
・model が null の時には要素数が 0 の IList<object> にする | |
思い付いたコード: | |
初版 | |
var values = new List<string>(((model as IEnumerable) ?? Enumerable.Empty<object>()).Cast<object>().Select(p => p.ToString())); | |
じんぐるさん提案の修正を入れた | |
var values = ((model as IEnumerable) ?? new object[0]).Cast<object>().Select(p => p.ToString()).ToList(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment