Exemplo n.º 1
0
 /// <summary>
 /// If the given <paramref name="value"/> is not effective, the algorithm searches
 /// for the first effective value in <paramref name="deflts"/>, otherwise the <paramref name="value"/> is returned.
 /// </summary>
 /// <returns><paramref name="value"/> if effective, otherwise the first effective value of
 /// <paramref name="deflts"/> if exists, otherwise <c>null</c>.</returns>
 /// <param name="value">The value to check and possible return.</param>
 /// <param name="deflts">An list of default values that must be tried all until a non-effective
 /// value is found, or the end of the list is reached.</param>
 /// <typeparam name="T">The type of elements over which the function is defined.</typeparam>
 /// <remarks>
 /// <para>If the list of default values is not effective as well, null is returned.</para>
 /// <para>It is still possible that the result is not effective if both <paramref name="value"/>
 /// and all items in <paramref name="deflt"/> are <c>null</c> (or the list itself is <c>null</c>).</para>
 /// </remarks>
 public static T IfNull <T> (this T value, IEnumerable <T> deflts)
     where T : class
 {
     if (value != null || deflts == null)
     {
         return(value);
     }
     else
     {
         return(Enumerable.FirstOrDefault(deflts, StandardFunctions.NotNull <T> ().Invoke));
     }
 }