/// <summary> /// Resolves the specified type by name in module and referenced (with a maximum depth) /// </summary> /// <param name="moduleDefinition">The module definition.</param> /// <param name="fullName">The full name.</param> /// <param name="ignoreSystem">if set to <c>true</c> [ignore system].</param> /// <param name="depth">The depth.</param> /// <returns></returns> private TypeDef Resolve(ModuleDef moduleDefinition, string fullName, bool ignoreSystem, int depth) { //Logger.WriteDebug("Trying to resolve in the following modules:"); //foreach (var module in moduleDefinition.GetSelfAndReferences(AssemblyResolver, ignoreSystem, 10)) // Logger.WriteDebug($" {module.FullName}"); //foreach (var assemblyRef in moduleDefinition.GetAssemblyRefs()) //{ // Logger.WriteDebug($"Ref '{assemblyRef.FullName}' from '{moduleDefinition.FullName}'"); // var assemblyDef = AssemblyResolver.Resolve(assemblyRef, moduleDefinition); // if (assemblyDef == null) // Logger.WriteError(" Can't resolve!"); // else // { // var m = assemblyDef.GetMainModule(); // Logger.WriteDebug($" Loaded {m.FullName}"); // } //} lock (_resolvedTypesByName) { var selfAndReferences = moduleDefinition.GetSelfAndReferences(AssemblyResolver, ignoreSystem, depth, Logging, IsMainModule(moduleDefinition)); return(selfAndReferences.SelectMany(referencedModule => referencedModule.GetTypes()).FirstOrDefault(t => Matches(t, fullName))); } }