ArchiMetrics.Analysis.Metrics.MemberNameResolver.TryResolveMemberSignatureString C# (CSharp) Method

TryResolveMemberSignatureString() public method

public TryResolveMemberSignatureString ( Microsoft.CodeAnalysis.SyntaxNode syntaxNode ) : string
syntaxNode Microsoft.CodeAnalysis.SyntaxNode
return string
		public string TryResolveMemberSignatureString(SyntaxNode syntaxNode)
		{
			Func<SyntaxNode, string> func;
			var dictionary = new Dictionary<SyntaxKind, Func<SyntaxNode, string>>
				                  {
					                  { SyntaxKind.MethodDeclaration, x => GetMethodSignatureString((MethodDeclarationSyntax)x) }, 
					                  { SyntaxKind.ConstructorDeclaration, x => GetConstructorSignatureString((ConstructorDeclarationSyntax)x) }, 
					                  { SyntaxKind.DestructorDeclaration, x => GetDestructorSignatureString((DestructorDeclarationSyntax)x) }, 
					                  { SyntaxKind.GetAccessorDeclaration, x => GetPropertyGetterSignatureString((AccessorDeclarationSyntax)x) }, 
									  { SyntaxKind.SetAccessorDeclaration, x => GetPropertySetterSignatureString((AccessorDeclarationSyntax)x) }, 
					                  { SyntaxKind.AddAccessorDeclaration, x => GetAddEventHandlerSignatureString((AccessorDeclarationSyntax)x) }, 
					                  { SyntaxKind.RemoveAccessorDeclaration, x => GetRemoveEventHandlerSignatureString((AccessorDeclarationSyntax)x) }
				                  };
			var kind = syntaxNode.Kind();
			return dictionary.TryGetValue(kind, out func)
				? func(syntaxNode)
				: string.Empty;
		}

Usage Example

Example #1
0
        private async Task <IMemberMetric> CalculateMemberMetric(SyntaxNode syntaxNode)
        {
            var analyzer               = new HalsteadAnalyzer();
            var halsteadMetrics        = analyzer.Calculate(syntaxNode);
            var memberName             = _nameResolver.TryResolveMemberSignatureString(syntaxNode);
            var source                 = CalculateClassCoupling(syntaxNode);
            var complexity             = CalculateCyclomaticComplexity(syntaxNode);
            var linesOfCode            = CalculateLinesOfCode(syntaxNode);
            var sourceLinesOfCode      = CalculateSourceLinesOfCode(syntaxNode);
            var numberOfParameters     = CalculateNumberOfParameters(syntaxNode);
            var numberOfLocalVariables = CalculateNumberOfLocalVariables(syntaxNode);
            var maintainabilityIndex   = CalculateMaintainablityIndex(complexity, linesOfCode, halsteadMetrics);
            var afferentCoupling       = await CalculateAfferentCoupling(syntaxNode).ConfigureAwait(false);

            var location   = syntaxNode.GetLocation();
            var lineNumber = location.GetLineSpan().StartLinePosition.Line;
            var filePath   = location.SourceTree == null ? string.Empty : location.SourceTree.FilePath;

            filePath = filePath.GetPathRelativeTo(_rootFolder);
            var accessModifier = GetAccessModifier(syntaxNode);
            IMemberDocumentation documentation = null;

            if (syntaxNode.SyntaxTree == Model.SyntaxTree)
            {
                var symbol = Model.GetDeclaredSymbol(syntaxNode);
                documentation = await _documentationFactory.Create(symbol, CancellationToken.None);
            }

            return(new MemberMetric(filePath,
                                    accessModifier,
                                    halsteadMetrics,
                                    lineNumber,
                                    linesOfCode,
                                    sourceLinesOfCode,
                                    maintainabilityIndex,
                                    complexity,
                                    memberName,
                                    source.AsArray(),
                                    numberOfParameters,
                                    numberOfLocalVariables,
                                    afferentCoupling,
                                    documentation));
        }