mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Add NotNull for IEnumerable<T> where T : struct
This commit is contained in:
parent
019bd9282b
commit
a5088bc10e
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
@ -37,14 +38,21 @@ namespace Wabbajack
|
||||
/// <summary>
|
||||
/// Converts and filters a nullable enumerable to a non-nullable enumerable
|
||||
/// </summary>
|
||||
public static IEnumerable<T> NotNull<T>(this IEnumerable<T?> e)
|
||||
public static IEnumerable<T> NotNull<T>(this IEnumerable<T?> enumerable)
|
||||
where T : class
|
||||
{
|
||||
// Filter out nulls
|
||||
return e.Where(e => e != null)
|
||||
return enumerable.Where(e => e != null)
|
||||
// Cast to non nullable type
|
||||
.Select(e => e!);
|
||||
}
|
||||
|
||||
public static IEnumerable<T> NotNull<T>(this IEnumerable<T?> enumerable) where T : struct
|
||||
{
|
||||
return enumerable
|
||||
.Where(x => x.HasValue)
|
||||
.Select(x => x!.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects items that are castable to the desired type
|
||||
|
Loading…
Reference in New Issue
Block a user