using System.Collections.Generic; using Mono.Cecil; namespace StardewModdingAPI.Framework.ModLoading { /// A minimal assembly definition resolver which resolves references to known assemblies. internal class AssemblyDefinitionResolver : DefaultAssemblyResolver { /********* ** Properties *********/ /// The known assemblies. private readonly IDictionary Loaded = new Dictionary(); /********* ** Public methods *********/ /// Add known assemblies to the resolver. /// The known assemblies. public void Add(params AssemblyDefinition[] assemblies) { foreach (AssemblyDefinition assembly in assemblies) { this.Loaded[assembly.Name.Name] = assembly; this.Loaded[assembly.Name.FullName] = assembly; } } /// Resolve an assembly reference. /// The assembly name. public override AssemblyDefinition Resolve(AssemblyNameReference name) => this.ResolveName(name.Name) ?? base.Resolve(name); /// Resolve an assembly reference. /// The assembly name. /// The assembly reader parameters. public override AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) => this.ResolveName(name.Name) ?? base.Resolve(name, parameters); /********* ** Private methods *********/ /// Resolve a known assembly definition based on its short or full name. /// The assembly's short or full name. private AssemblyDefinition ResolveName(string name) { return this.Loaded.ContainsKey(name) ? this.Loaded[name] : null; } } }