Esempio n. 1
0
        /// <summary>
        /// Searches the specified assembly for Analyzer instances and loads them.
        /// </summary>
        /// <param name="analyzerAssembly">The assembly to consume.</param>
        protected void ConsumeAssembly(Assembly analyzerAssembly)
        {
            if (analyzerAssembly == null)
            {
                throw new ArgumentNullException(nameof(analyzerAssembly));
            }

            AnalyzerLoadContext loadContext = new AnalyzerLoadContext();

            AnalyzerProviderAttribute attr =
                (AnalyzerProviderAttribute)analyzerAssembly.GetCustomAttribute(typeof(AnalyzerProviderAttribute));

            if (attr != null && attr.ProviderType != null)
            {
                IAnalyzerProvider analyzerProvider = Activator.CreateInstance(attr.ProviderType) as IAnalyzerProvider;
                if (analyzerProvider != null)
                {
                    foreach (Analyzer analyzer in analyzerProvider.GetAnalyzers())
                    {
                        loadContext.Reset(analyzer);
                        OnAnalyzerLoaded(loadContext);
                        if (loadContext.ShouldRun)
                        {
                            _analyzers.Add(loadContext.Analyzer);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Called when each Analyzer is loaded.
 /// </summary>
 /// <param name="loadContext">The context for the Analyzer load.</param>
 protected virtual void OnAnalyzerLoaded(AnalyzerLoadContext loadContext)
 {
     // All analyzers are run by default.
 }