コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【C#】条件を満たす場合にのみ Prepend する拡張メソッド

概要

using System.Collections.Generic;
using System.Linq;

namespace Kogane
{
    public static class EnumerableExtensionMethods
    {
        public static IEnumerable<T> PrependIf<T>
        (
            this IEnumerable<T> self,
            bool                conditional,
            T                   element
        )
        {
            return !conditional ? self : self.Prepend( element );
        }
    }
}