Пример #1
0
        /// Build contexts' list and lookup according to collected Component-Types
        private void InitAllContexts()
        {
            var defaultContextName = ContextAttribute.GetName <Default>();

            var comps = CollectAllComponents();

            var contextList = new List <Context>();

            _contextLookup = new Dictionary <string, Context>();

            foreach (var cc in comps)
            {
                var name      = cc.Key;
                var list      = cc.Value;
                var isDefault = name == defaultContextName;

                list.Sort((x, y) => string.CompareOrdinal(x.FullName, y.FullName));

                var c = new Context(list.Count, startCreationIndex, new ContextInfo(name, list.ToArray(), isDefault), GetAERC());

                _contextLookup[name] = c;
                contextList.Add(c);
            }

            _defaultContext = _contextLookup[defaultContextName];
            _contextList    = contextList.ToArray();
        }
Пример #2
0
        /// Collect all Compoent-Types in current domain
        private static Dictionary <string, List <Type> > CollectAllComponents()
        {
            var defaultContextName = ContextAttribute.GetName <Default>();

            var compType = typeof(IComponent);
            var types    = AppDomain.CurrentDomain.GetAssemblies()
                           .SelectMany(s => s.GetTypes())
                           .Where(p => p.IsClass && p.IsPublic && !p.IsAbstract &&
                                  compType.IsAssignableFrom(p));

            var comps = new Dictionary <string, List <Type> >();

            comps[defaultContextName] = new List <Type>();

            var attrType = typeof(ContextAttribute);

            foreach (var t in types)
            {
                var attribs = t.GetCustomAttributes(attrType, false);

                if (attribs == null || attribs.Length <= 0)
                {
                    CollectComponent(comps, defaultContextName, t);
                }
                else
                {
                    foreach (var attr in attribs)
                    {
                        CollectComponent(comps, ((ContextAttribute)attr).name, t);
                    }
                }
            }

            return(comps);
        }
Пример #3
0
 public static Context Get <S>() where S : ContextAttribute
 {
     return(sharedInstance._contextLookup[ContextAttribute.GetName <S>()]);
 }
Пример #4
0
 public Context GetContext <S>() where S : ContextAttribute
 {
     return(_contextLookup[ContextAttribute.GetName <S>()]);
 }
Пример #5
0
 public Context GetContext <S>() where S : ContextAttribute
 {
     return(GetContext(ContextAttribute.GetName <S>()));
 }