Browse Source

Fixed HasInterface

Added NonNull LINQ method
pull/46/head
Anairkoen Schno 5 years ago
parent
commit
6f605e0007
5 changed files with 42 additions and 10 deletions
  1. +3
    -3
      BSIPA-ModList/UI/WarningUI.cs
  2. +3
    -3
      IPA.Loader/Loader/PluginLoader.cs
  3. +1
    -1
      IPA.Loader/Updating/BeatMods/Updater.cs
  4. +35
    -3
      IPA.Loader/Utilities/Utils.cs
  5. BIN
      Refs/UnityEngine.CoreModule.Net4.dll

+ 3
- 3
BSIPA-ModList/UI/WarningUI.cs View File

@ -86,9 +86,9 @@ namespace BSIPA_ModList.UI
_warningsQueue.Clear();
var enabledPlugins = PluginManager.AllPlugins.Select(p => p.Metadata).Where(x => x.Id != null).ToDictionary(x => x.Id, y => y.Version);
var ignoredPlugins = PluginLoader.ignoredPlugins.Where(x => x.Id != null).ToDictionary(x => x.Id, y => y.Version);
var disabledPlugins = PluginManager.DisabledPlugins.Where(x => x.Id != null).ToDictionary(x => x.Id, y => y.Version);
var enabledPlugins = PluginManager.AllPlugins.Select(p => p.Metadata).NonNull(x => x.Id).ToDictionary(x => x.Id, y => y.Version);
var ignoredPlugins = PluginLoader.ignoredPlugins.NonNull(x => x.Id).ToDictionary(x => x.Id, y => y.Version);
var disabledPlugins = PluginManager.DisabledPlugins.NonNull(x => x.Id).ToDictionary(x => x.Id, y => y.Version);
// iterate only disabled and ignored, as thats where missing deps can end up
foreach (var meta in PluginManager.DisabledPlugins.Concat(PluginLoader.ignoredPlugins))


+ 3
- 3
IPA.Loader/Loader/PluginLoader.cs View File

@ -311,7 +311,7 @@ namespace IPA.Loader
if (!meta.IsSelf)
{
var resc = meta.PluginType.Module.Resources.Select(r => r as EmbeddedResource)
.Where(r => r != null)
.NonNull()
.FirstOrDefault(r => r.Name == name);
if (resc == null)
{
@ -488,7 +488,7 @@ namespace IPA.Loader
{
var metadata = new List<PluginMetadata>();
var pluginsToLoad = new Dictionary<string, Version>();
var disabledLookup = DisabledPlugins.Where(m => m.Id != null).ToDictionary(m => m.Id, m => m.Version);
var disabledLookup = DisabledPlugins.NonNull(m => m.Id).ToDictionary(m => m.Id, m => m.Version);
foreach (var meta in PluginsMetadata)
{
bool load = true;
@ -705,7 +705,7 @@ namespace IPA.Loader
{
InitFeatures();
DisabledPlugins.ForEach(Load); // make sure they get loaded into memory so their metadata and stuff can be read more easily
return PluginsMetadata.Select(InitPlugin).Where(p => p != null).ToList();
return PluginsMetadata.Select(InitPlugin).NonNull().ToList();
}
}
}

+ 1
- 1
IPA.Loader/Updating/BeatMods/Updater.cs View File

@ -395,7 +395,7 @@ namespace IPA.Updating.BeatMods
}
var ver = modsMatching.Value
.Where(nullCheck => nullCheck != null) // entry is not null
.NonNull() // entry is not null
.Where(versionCheck => versionCheck.GameVersion == BeatSaber.GameVersion) // game version matches
.Where(approvalCheck => approvalCheck.Status == ApiEndpoint.Mod.ApprovedStatus) // version approved
// TODO: fix; it seems wrong somehow


+ 35
- 3
IPA.Loader/Utilities/Utils.cs View File

@ -178,7 +178,7 @@ namespace IPA.Utilities
/// </summary>
/// <param name="l">the left 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>&lt; 0 if l is less than r, 0 if they are equal in the numeric portion, or &gt; 0 if l is greater than r</returns>
public static int VersionCompareNoPrerelease(SemVer.Version l, SemVer.Version r)
{
var cmpVal = l.Major - r.Major;
@ -188,10 +188,42 @@ namespace IPA.Utilities
cmpVal = l.Patch - r.Patch;
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)
{
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


BIN
Refs/UnityEngine.CoreModule.Net4.dll View File


Loading…
Cancel
Save