|
@ -178,7 +178,7 @@ namespace IPA.Utilities |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="l">the left value</param>
|
|
|
/// <param name="l">the left value</param>
|
|
|
/// <param name="r">the right value</param>
|
|
|
/// <param name="r">the right value</param>
|
|
|
/// <returns>-1 if l is less than r, 0 if they are equal in the numeric portion, or 1 if l is greater than r</returns>
|
|
|
|
|
|
|
|
|
/// <returns>< 0 if l is less than r, 0 if they are equal in the numeric portion, or > 0 if l is greater than r</returns>
|
|
|
public static int VersionCompareNoPrerelease(SemVer.Version l, SemVer.Version r) |
|
|
public static int VersionCompareNoPrerelease(SemVer.Version l, SemVer.Version r) |
|
|
{ |
|
|
{ |
|
|
var cmpVal = l.Major - r.Major; |
|
|
var cmpVal = l.Major - r.Major; |
|
@ -188,10 +188,42 @@ namespace IPA.Utilities |
|
|
cmpVal = l.Patch - r.Patch; |
|
|
cmpVal = l.Patch - r.Patch; |
|
|
return cmpVal; |
|
|
return cmpVal; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// LINQ extension method that filters <see langword="null"/> elements out of an enumeration.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T">the type of the enumeration</typeparam>
|
|
|
|
|
|
/// <param name="self">the enumeration to filter</param>
|
|
|
|
|
|
/// <returns>a filtered enumerable</returns>
|
|
|
|
|
|
public static IEnumerable<T> NonNull<T>(this IEnumerable<T> self) where T : class |
|
|
|
|
|
=> self.Where(o => o != null); |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// LINQ extension method that filters <see langword="null"/> elements out of an enumeration based on a converter.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T">the type of the enumeration</typeparam>
|
|
|
|
|
|
/// <typeparam name="U">the type to compare to null</typeparam>
|
|
|
|
|
|
/// <param name="self">the enumeration to filter</param>
|
|
|
|
|
|
/// <param name="pred">the predicate to select for filtering</param>
|
|
|
|
|
|
/// <returns>a filtered enumerable</returns>
|
|
|
|
|
|
public static IEnumerable<T> NonNull<T, U>(this IEnumerable<T> self, Func<T, U> pred) where T : class where U : class |
|
|
|
|
|
=> self.Where(o => pred(o) != null); |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// LINQ extension method that filters <see langword="null"/> elements from an enumeration of nullable types.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T">the underlying type of the nullable enumeration</typeparam>
|
|
|
|
|
|
/// <param name="self">the enumeration to filter</param>
|
|
|
|
|
|
/// <returns>a filtered enumerable</returns>
|
|
|
|
|
|
public static IEnumerable<T> NonNull<T>(this IEnumerable<T?> self) where T : struct |
|
|
|
|
|
=> self.Where(o => o != null).Select(o => o.Value); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal static bool HasInterface(this TypeDefinition type, string interfaceFullName) |
|
|
internal static bool HasInterface(this TypeDefinition type, string interfaceFullName) |
|
|
{ |
|
|
{ |
|
|
return (type.Interfaces.Any(i => i.InterfaceType.FullName == interfaceFullName) |
|
|
|
|
|
|| type.Interfaces.Any(t => HasInterface(t.InterfaceType.Resolve(), interfaceFullName))); |
|
|
|
|
|
|
|
|
return (type?.Interfaces?.Any(i => i.InterfaceType.FullName == interfaceFullName) ?? false) |
|
|
|
|
|
|| (type?.Interfaces?.Any(t => HasInterface(t?.InterfaceType?.Resolve(), interfaceFullName)) ?? false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#if NET4
|
|
|
#if NET4
|
|
|