示例#1
0
        public void Test_Should_Add_SingleBean()
        {
            var beanGroup = new BeanGroup();

            beanGroup.Add(typeof(SingleBean));
            Assert.Contains(beanGroup.SingleBeans, x => x.TBean == typeof(SingleBean));
        }
示例#2
0
        public void Test_Should_Add_InterfaceWithBean()
        {
            var beanGroup = new BeanGroup();

            beanGroup.Add(typeof(ILangBean), typeof(SpanishLangBean));
            var beanCollection = beanGroup.InterfaceBeans.FirstOrDefault(x => x.TInterface == typeof(ILangBean));

            Assert.NotNull(beanCollection);
            var beanData = beanCollection.FindBean(new BeanConfig("Spanish", false));

            Assert.NotNull(beanData);
            Assert.Equal(typeof(SpanishLangBean), beanData.TBean);
        }
示例#3
0
 /// <summary>
 /// Add a list of beans to bean's group
 /// </summary>
 /// <param name="beanGroup">Bean's group</param>
 /// <param name="tbeans">List of beans (classes marked as bean)</param>
 private void AddTypesToBeanGroup(BeanGroup beanGroup, List <Type> tbeans)
 {
     tbeans.ForEach(tbean =>
     {
         var interfaces = GetDirectInterfaces(tbean);
         if (interfaces.Count > 0)
         {
             interfaces.ForEach(tinterface => beanGroup.Add(tinterface, tbean));
         }
         else
         {
             beanGroup.Add(tbean);
         }
     });
 }
示例#4
0
        /// <summary>
        /// Find all classes marked with bean attributes in assemblyNames list.
        /// All found classes in ignoreBeans list will be ignored.
        /// </summary>
        /// <param name="assemblyNames">Name of assemblies where classes with bean attribute are looked for</param>
        /// <param name="ignoreBeans">Beans to be ignored</param>
        /// <returns>Group of beans (with or without interface)</returns>
        public BeanGroup GetBeanTypes(List <AssemblyName> assemblyNames, List <Type> ignoreBeans = null)
        {
            var beanGroup = new BeanGroup();

            assemblyNames.ToList().ForEach(assemblyName =>
            {
                var assembly = Assembly.Load(assemblyName);
                var tbeans   = GetBeanTypes(assembly);
                if (ignoreBeans != null)
                {
                    tbeans = tbeans.Except(ignoreBeans).ToList();
                }
                AddTypesToBeanGroup(beanGroup, tbeans);
            });
            return(beanGroup);
        }