Browse Source

Minor code quality changes in PluginInitInjector

pull/46/head
Anairkoen Schno 5 years ago
parent
commit
66e8319a6d
1 changed files with 4 additions and 4 deletions
  1. +4
    -4
      IPA.Loader/Loader/PluginInitInjector.cs

+ 4
- 4
IPA.Loader/Loader/PluginInitInjector.cs View File

@ -33,7 +33,7 @@ namespace IPA.Loader
/// <param name="injector">the function to call for injection.</param> /// <param name="injector">the function to call for injection.</param>
public static void AddInjector(Type type, InjectParameter injector) public static void AddInjector(Type type, InjectParameter injector)
{ {
injectors.Add(new Tuple<Type, InjectParameter>(type, injector));
injectors.Add(Tuple.Create(type, injector));
} }
private static readonly List<Tuple<Type, InjectParameter>> injectors = new List<Tuple<Type, InjectParameter>> private static readonly List<Tuple<Type, InjectParameter>> injectors = new List<Tuple<Type, InjectParameter>>
@ -60,14 +60,14 @@ namespace IPA.Loader
var initArgs = new List<object>(); var initArgs = new List<object>();
var initParams = init.GetParameters(); var initParams = init.GetParameters();
Dictionary<Tuple<Type, InjectParameter>, object> previousValues =
new Dictionary<Tuple<Type, InjectParameter>, object>(injectors.Count);
var previousValues = new Dictionary<Tuple<Type, InjectParameter>, object>(injectors.Count);
foreach (var param in initParams) foreach (var param in initParams)
{ {
var paramType = param.ParameterType; var paramType = param.ParameterType;
var value = paramType.GetDefault(); var value = paramType.GetDefault();
// TODO: make this work on closest match
foreach (var pair in injectors.Where(t => paramType.IsAssignableFrom(t.Item1))) foreach (var pair in injectors.Where(t => paramType.IsAssignableFrom(t.Item1)))
{ {
object prev = null; object prev = null;
@ -75,7 +75,7 @@ namespace IPA.Loader
prev = previousValues[pair]; prev = previousValues[pair];
var val = pair.Item2?.Invoke(prev, param, meta); var val = pair.Item2?.Invoke(prev, param, meta);
if (previousValues.ContainsKey(pair)) if (previousValues.ContainsKey(pair))
previousValues[pair] = val; previousValues[pair] = val;
else else


Loading…
Cancel
Save