Unstable 0.16.0.0

This commit is contained in:
Markus Isberg
2022-01-14 01:28:24 +09:00
parent d9baeaa2e1
commit 7d6421a548
237 changed files with 6430 additions and 2205 deletions
@@ -133,7 +133,7 @@ namespace Barotrauma.Extensions
return source.Count(predicate) > 1;
}
}
public static IEnumerable<T> ToEnumerable<T>(this T item)
{
yield return item;
@@ -196,5 +196,28 @@ namespace Barotrauma.Extensions
}
return -1;
}
/// <summary>
/// Same as FirstOrDefault but will always return null instead of default(T) when no element is found
/// </summary>
public static T? FirstOrNull<T>(this IEnumerable<T> source, Func<T, bool> predicate) where T : struct
{
if (source.FirstOrDefault(predicate) is var first && !first.Equals(default(T)))
{
return first;
}
return null;
}
public static T? FirstOrNull<T>(this IEnumerable<T> source) where T : struct
{
if (source.FirstOrDefault() is var first && !first.Equals(default(T)))
{
return first;
}
return null;
}
}
}