Пример #1
0
        private IPageElementConstructor <TGroup, TPage> FindConstructor(Type type, IAttributeSet atts)
        {
            if (atts == null)
            {
                throw new ArgumentNullException(nameof(atts));
            }

            IPageElementConstructor <TGroup, TPage> constr = null;

            if (atts.Has <ISpecificConstructorAttribute>())
            {
                var constrType = atts.Get <ISpecificConstructorAttribute>().ConstructorType;

                var constrs = m_SpecificConstructors.Where(c => constrType.IsAssignableFrom(c.Key));

                if (constrs.Count() == 1)
                {
                    constr = constrs.First().Value;
                }
                else if (!constrs.Any())
                {
                    throw new ConstructorNotFoundException(type, "Specific constructor is not registered");
                }
                else
                {
                    throw new ConstructorNotFoundException(type, "Too many constructors registered");
                }
            }
            else
            {
                if (!m_DefaultConstructors.TryGetValue(type, out constr))
                {
                    constr = m_DefaultConstructors.FirstOrDefault(
                        t => t.Key.IsAssignableFrom(type)).Value;

                    if (constr == null)
                    {
                        foreach (var specType in SpecialTypes.FindMathingSpecialTypes(type))
                        {
                            if (m_SpecialTypeConstructors.TryGetValue(specType, out constr))
                            {
                                break;
                            }
                        }
                    }
                }
            }

            if (constr != null)
            {
                return(constr);
            }
            else
            {
                throw new ConstructorNotFoundException(type);
            }
        }