diff --git a/IPA.Loader/Utilities/EnumerableExtensions.cs b/IPA.Loader/Utilities/EnumerableExtensions.cs index 61ba93a4..f9220e89 100644 --- a/IPA.Loader/Utilities/EnumerableExtensions.cs +++ b/IPA.Loader/Utilities/EnumerableExtensions.cs @@ -41,5 +41,35 @@ namespace IPA.Utilities IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } + + /// + /// LINQ extension method that filters elements out of an enumeration. + /// + /// the type of the enumeration + /// the enumeration to filter + /// a filtered enumerable + public static IEnumerable NonNull(this IEnumerable self) where T : class + => self.Where(o => o != null); + + /// + /// LINQ extension method that filters elements out of an enumeration based on a converter. + /// + /// the type of the enumeration + /// the type to compare to null + /// the enumeration to filter + /// the predicate to select for filtering + /// a filtered enumerable + public static IEnumerable NonNull(this IEnumerable self, Func pred) where T : class where U : class + => self.Where(o => pred(o) != null); + + /// + /// LINQ extension method that filters elements from an enumeration of nullable types. + /// + /// the underlying type of the nullable enumeration + /// the enumeration to filter + /// a filtered enumerable + public static IEnumerable NonNull(this IEnumerable self) where T : struct + => self.Where(o => o != null).Select(o => o.Value); + } } diff --git a/IPA.Loader/Utilities/Utils.cs b/IPA.Loader/Utilities/Utils.cs index bfa153e1..8226d583 100644 --- a/IPA.Loader/Utilities/Utils.cs +++ b/IPA.Loader/Utilities/Utils.cs @@ -189,36 +189,6 @@ namespace IPA.Utilities return cmpVal; } - /// - /// LINQ extension method that filters elements out of an enumeration. - /// - /// the type of the enumeration - /// the enumeration to filter - /// a filtered enumerable - public static IEnumerable NonNull(this IEnumerable self) where T : class - => self.Where(o => o != null); - - /// - /// LINQ extension method that filters elements out of an enumeration based on a converter. - /// - /// the type of the enumeration - /// the type to compare to null - /// the enumeration to filter - /// the predicate to select for filtering - /// a filtered enumerable - public static IEnumerable NonNull(this IEnumerable self, Func pred) where T : class where U : class - => self.Where(o => pred(o) != null); - - /// - /// LINQ extension method that filters elements from an enumeration of nullable types. - /// - /// the underlying type of the nullable enumeration - /// the enumeration to filter - /// a filtered enumerable - public static IEnumerable NonNull(this IEnumerable self) where T : struct - => self.Where(o => o != null).Select(o => o.Value); - - internal static bool HasInterface(this TypeDefinition type, string interfaceFullName) {