Inheritance: ICodeMetricsCalculator
 async void Analyzeblock(CodeBlockAnalysisContext obj)
 {
     var metricsCalculator = new CodeMetricsCalculator();
     var metrics = await metricsCalculator.Calculate(new List<SyntaxTree> { CSharpSyntaxTree.ParseText(obj.CodeBlock.ToString()) });
     var functionMetric = metrics.ElementAt(0).TypeMetrics.ElementAt(0).MemberMetrics.ElementAt(0);
     //var settings = SettingsHelper.GetSettings(obj.Options);
     var settings = new Settings();
     CheckComplexity(obj, functionMetric.CyclomaticComplexity, settings.MethodSettings);
     CheckNumberOfParameters(obj, functionMetric.NumberOfParameters, settings.MethodSettings);
     CheckLinesOfCode(obj, functionMetric.LinesOfCode, settings.MethodSettings);
 }
        private static async Task<IEnumerable<INamespaceMetric>> RunCodeMetrics(MetricConfiguration configuration)
        {
            Console.WriteLine("Loading Solution");
            var solutionProvider = new SolutionProvider();
            var solution = await solutionProvider.Get(configuration.Solution).ConfigureAwait(false);
            Console.WriteLine("Solution loaded");

            var projects = solution.Projects.Where(p => !configuration.IgnoredProjects.Contains(p.Name)).ToList();

            Console.WriteLine("Loading metrics, wait it may take a while.");

            var metrics = new List<IEnumerable<INamespaceMetric>>();
            var metricsCalculator = new CodeMetricsCalculator(new CalculationConfiguration
            {
                NamespacesIgnored = configuration.IgnoredNamespaces,
                TypesIgnored = configuration.IgnoredTypes
            });
            foreach (var project in projects)
            {
                var calculate = await metricsCalculator.Calculate(project, solution);
                metrics.Add(calculate);
            }

            return metrics.SelectMany(nm => nm);
        }
Beispiel #3
0
		public Metrics()
		{
			_codeMetricsCalculator = new CodeMetricsCalculator();
			_projectMetricsCalculator = new ProjectMetricsCalculator(_codeMetricsCalculator);
		}