예제 #1
0
        /// <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)
            {
            }
        }
        public void TypeWithDefaultConstructor()
        {
            var result = _builder.Build();
            var type   = GetTypeByNameAndAssert(result, nameof(TypeWithDefaultConstructor));

            Assert.True(type.HasDefaultConstructor);
            Assert.True(type.IsPublic);
            Assert.False(type.IsValueType);
        }