private static TypeDefinition GetTypeByNameAndAssert(ReflectionMetadataResult result, string name) { var types = result.FindTypesByName(name).ToArray(); Assert.Equal(1, types.Length); return(types.First()); }
/// <summary> /// Creates a new plugin loader /// </summary> /// <param name="root">root folder, default is relative to executing assemlby</param> /// <param name="patterns"></param> public PluginLoader(ILogger logger = null, string rootDir = ".", IEnumerable <string> patterns = null) { logger.LogDebug("Getting files from {relpath}", rootDir); var files = new List <string>(); if (patterns == null) { files.AddRange(Glob.Files(rootDir, "**/*.dll")); } else { foreach (var pattern in patterns) { files.AddRange(Glob.Files(rootDir, Regex.Replace(pattern, @"^\./", ""))); } } logger.LogDebug("Found {fct} files:\n {@files}", files.Count, files); var builder = new ReflectionMetadataBuilder(); foreach (var file in files) { try { builder.AddAssembly(Path.Combine(rootDir, file)); } catch (Exception) { } } builder.AddReferenceOnlyAssemblyByType <object>(); // adds the corlib try { metaData = builder.Build(true); } catch (AggregateException aex) { throw; } catch (Exception ex) { } }