ArchiMetrics.Analysis.Metrics.TypeMetricsCalculator.CalculateFrom C# (CSharp) Method

CalculateFrom() public method

public CalculateFrom ( TypeDeclarationSyntaxInfo typeNode, IEnumerable metrics ) : Task
typeNode TypeDeclarationSyntaxInfo
metrics IEnumerable
return Task
		public async Task<ITypeMetric> CalculateFrom(TypeDeclarationSyntaxInfo typeNode, IEnumerable<IMemberMetric> metrics)
		{
			var memberMetrics = metrics.AsArray();
			var type = typeNode.Syntax;
			var symbol = Model.GetDeclaredSymbol(type);
			var documentation = await _documentationFactory.Create(symbol, CancellationToken.None);
			var metricKind = GetMetricKind(type);
			var source = CalculateClassCoupling(type, memberMetrics);
			var depthOfInheritance = CalculateDepthOfInheritance(type);
			var cyclomaticComplexity = memberMetrics.Sum(x => x.CyclomaticComplexity);
			var linesOfCode = memberMetrics.Sum(x => x.LinesOfCode);
			var maintainabilityIndex = CalculateAveMaintainabilityIndex(memberMetrics);
			var afferentCoupling = await CalculateAfferentCoupling(type);
			var efferentCoupling = GetEfferentCoupling(type, symbol);
			var instability = (double)efferentCoupling / (efferentCoupling + afferentCoupling);
			var modifier = GetAccessModifier(type.Modifiers);
			return new TypeMetric(
				symbol.IsAbstract,
				metricKind,
				modifier,
				memberMetrics,
				linesOfCode,
				cyclomaticComplexity,
				maintainabilityIndex,
				depthOfInheritance,
				source,
				type.GetName(),
				afferentCoupling,
				efferentCoupling,
				instability,
				documentation);
		}

Usage Example

		private async Task<Tuple<Compilation, ITypeMetric>> CalculateTypeMetrics(Solution solution, Compilation compilation, TypeDeclaration typeNodes, IEnumerable<IMemberMetric> memberMetrics)
		{
			if (typeNodes.SyntaxNodes.Any())
			{
				var tuple = await VerifyCompilation(compilation, typeNodes.SyntaxNodes.First()).ConfigureAwait(false);
				var semanticModel = tuple.Item2;
				compilation = tuple.Item1;
				var typeNode = tuple.Item3;
				var calculator = new TypeMetricsCalculator(semanticModel, solution, _typeDocumentationFactory);
				var metrics = await calculator.CalculateFrom(typeNode, memberMetrics);
				return new Tuple<Compilation, ITypeMetric>(
					compilation,
					metrics);
			}

			return null;
		}