private bool NeedToCall(QueryDependentFeatureAttribute customAttribute)
 {
     if (customAttribute == null)
     {
         return(false);
     }
     if (!featureNumbers.ContainsKey(customAttribute.FeatureName) || customAttribute.Ignore)
     {
         return(false);
     }
     return(true);
 }
        public QueryDependentFeatureCalculator(FeatureList featureList)
        {
            Console.WriteLine("Initializing Query dependent feature calculator");
            var featuresToCalculate =
                featureList.Features.Where(f => f.QueryDependent && f.Ignore == false);

            featureNumbers = featuresToCalculate.ToDictionary(f => f.FeatureName, f => f.Number);
            Assembly executingAssembly = Assembly.GetExecutingAssembly();

            foreach (Type type in executingAssembly.GetTypes())
            {
                var          callData    = new List <KeyValuePair <Attribute, MethodInfo> >();
                MethodInfo[] methodInfos = type.GetMethods();
                object       instance    = null;
                foreach (MethodInfo methodInfo in methodInfos)
                {
                    QueryDependentFeatureAttribute featureAttribute =
                        methodInfo.GetCustomAttributes(typeof(QueryDependentFeatureAttribute), false).OfType <QueryDependentFeatureAttribute>().
                        FirstOrDefault();
                    if (NeedToCall(featureAttribute))
                    {
                        if (instance == null)
                        {
                            instance = (Activator.CreateInstance(type));
                        }
                        callData.Add(new KeyValuePair <Attribute, MethodInfo>(featureAttribute, methodInfo));
                    }
                }
                if (callData.Any())
                {
                    methodsToCall.Add(new MethodToCall {
                        Instance = instance, CallData = callData
                    });
                }
            }
        }