Наследование: Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker
Пример #1
0
		public async Task<IEnumerable<IMemberMetric>> Calculate(TypeDeclarationSyntaxInfo typeNode)
		{
			var walker = new MemberCollector();
			var members = walker.GetMembers(typeNode).AsArray();
			if ((typeNode.Syntax is ClassDeclarationSyntax
				|| typeNode.Syntax is StructDeclarationSyntax)
				&& members.All(m => m.Kind() != SyntaxKind.ConstructorDeclaration))
			{
				var defaultConstructor = SyntaxFactory.ConstructorDeclaration(typeNode.Name)
											   .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)))
											   .WithBody(SyntaxFactory.Block());
				members = members.Concat(new[] { defaultConstructor }).AsArray();
			}

			var metrics = await CalculateMemberMetrics(members).ConfigureAwait(false);
			return metrics.AsArray();
		}
        public async Task <IEnumerable <IMemberMetric> > Calculate(TypeDeclarationSyntaxInfo typeNode)
        {
            var walker  = new MemberCollector();
            var members = walker.GetMembers(typeNode).AsArray();

            if ((typeNode.Syntax is ClassDeclarationSyntax ||
                 typeNode.Syntax is StructDeclarationSyntax) &&
                members.All(m => m.Kind() != SyntaxKind.ConstructorDeclaration))
            {
                var defaultConstructor = SyntaxFactory.ConstructorDeclaration(typeNode.Name)
                                         .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)))
                                         .WithBody(SyntaxFactory.Block());
                members = members.Concat(new[] { defaultConstructor }).AsArray();
            }

            var metrics = await CalculateMemberMetrics(members).ConfigureAwait(false);

            return(metrics.AsArray());
        }