Пример #1
0
        private IEnumerable <TType> GetRules <TType>(ICalidusRuleConfigurationFactory configFactory)
            where TType : IRule
        {
            List <TType> result = new List <TType>();

            foreach (Type aType in _parsed)
            {
                TType ruleInstance = default(TType);

                //make sure to ignore the interface itself
                if (typeof(TType).IsAssignableFrom(aType))
                {
                    try
                    {
                        //not in default, try for a no-args constructor
                        if (aType.GetConstructor(new Type[] { }) != null)
                        {
                            ruleInstance = _instanceCreator.CreateInstanceOf <TType>(aType);
                        }
                        //try the factory
                        else
                        {
                            ruleInstance = _instanceCreator.CreateInstanceOf <TType>(aType, configFactory.GetRuleConfigurationFor(aType).ArgumentArray);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ruleInstance == null)
                        {
                            throw new CalidusException(String.Format(_exMsg, aType.Name), ex);
                        }
                    }

                    if (ruleInstance == null)
                    {
                        throw new CalidusException(String.Format(_exMsg, aType.Name));
                    }

                    result.Add(ruleInstance);
                }
            }

            return(result);
        }