当前位置: 首页>>代码示例>>C#>>正文


C# ConstructorDeclarationSyntax.WithParameterList方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax.WithParameterList方法的典型用法代码示例。如果您正苦于以下问题:C# ConstructorDeclarationSyntax.WithParameterList方法的具体用法?C# ConstructorDeclarationSyntax.WithParameterList怎么用?C# ConstructorDeclarationSyntax.WithParameterList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax的用法示例。


在下文中一共展示了ConstructorDeclarationSyntax.WithParameterList方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitConstructorDeclaration

        public override SyntaxNode VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
        {
            if(this._targetConstructor == null || node.ParameterList.ToString() == this._targetConstructor.ParameterList.ToString())
            {
                var fieldName = this._relatedField.Declaration.Variables
                    .Select(p => p.Identifier.Text)
                    .FirstOrDefault();

                var paramName = fieldName.TrimStart('_');

                if (this._rewriteParams)
                {
                    var newParam = SyntaxFactory.Parameter(SyntaxFactory.Identifier(paramName))
                                .WithType(this._relatedField.Declaration.Type);

                    var newConstructorParams = node.ParameterList.AddParameters(newParam);

                    node = node.WithParameterList(newConstructorParams);
                }

                var newStatement = SyntaxExtenders.AssignmentStatement("this." + fieldName, paramName);
                var newStatements = node.Body.Statements.Insert(0, newStatement);

                node = node.WithBody(node.Body.WithStatements(newStatements));
            }

            return base.VisitConstructorDeclaration(node);
        }
开发者ID:yohney,项目名称:common-refactorings-plugin,代码行数:28,代码来源:AlterConstructorRewriter.cs

示例2: VisitConstructorDeclaration

        public override SyntaxNode VisitConstructorDeclaration(ConstructorDeclarationSyntax constructorDeclaration)
        {
            if (constructor == constructorDeclaration)
            {
                var type = field.Declaration.Type;
                var variable = RoslynExtensions.GetFieldName(field);
                string parameter = variable;

                if(variable.StartsWith("_"))
                {
                    parameter = variable.Substring(1);
                }
                else
                {
                    variable = "this." + variable;
                }

                //var typeString = type.ToString();
                //if (typeString.StartsWith("I"))
                    //name = typeString.Substring(1);

                //name = Char.ToLowerInvariant(name[0]) + name.Substring(1);
                var p = SyntaxFactory.Parameter(
                    new SyntaxList<AttributeListSyntax>(),
                    new SyntaxTokenList(),
                    type,
                    SyntaxFactory.Identifier(parameter),
                    null);

                var parameters = constructorDeclaration.ParameterList.AddParameters(p);
                var body = constructorDeclaration.Body;
                var statement = SyntaxFactory.ParseStatement(variable + " = " + parameter + ";" + Environment.NewLine);//.WithLeadingTrivia(SyntaxFactory.Tab, SyntaxFactory.Tab);
                body = body.AddStatements(statement);

                return constructorDeclaration.WithParameterList(parameters).WithBody(body); //(BlockSyntax)formatted);
            }

            return base.VisitConstructorDeclaration(constructorDeclaration);
        }
开发者ID:OsvaldoJ,项目名称:orchardizer,代码行数:39,代码来源:ConstructorRewriter.cs

示例3: ReformatConstructorDeclaration

        private static ConstructorDeclarationSyntax ReformatConstructorDeclaration(ConstructorDeclarationSyntax constructorDeclaration, IndentationOptions indentationOptions, SyntaxTrivia newLine)
        {
            var constructorInitializer = constructorDeclaration.Initializer;

            var newParameterList = constructorDeclaration.ParameterList
                .WithTrailingTrivia(constructorDeclaration.ParameterList.GetTrailingTrivia().WithoutTrailingWhitespace().Add(newLine));

            var indentationSteps = IndentationHelper.GetIndentationSteps(indentationOptions, constructorDeclaration);
            var indentation = IndentationHelper.GenerateWhitespaceTrivia(indentationOptions, indentationSteps + 1);

            var newColonTrailingTrivia = constructorInitializer.ColonToken.TrailingTrivia.WithoutTrailingWhitespace();

            var newColonToken = constructorInitializer.ColonToken
                .WithLeadingTrivia(indentation)
                .WithTrailingTrivia(newColonTrailingTrivia);

            var newInitializer = constructorInitializer
                .WithColonToken(newColonToken)
                .WithThisOrBaseKeyword(constructorInitializer.ThisOrBaseKeyword.WithLeadingTrivia(SyntaxFactory.Space));

            return constructorDeclaration
                .WithParameterList(newParameterList)
                .WithInitializer(newInitializer);
        }
开发者ID:Noryoko,项目名称:StyleCopAnalyzers,代码行数:24,代码来源:SA1128CodeFixProvider.cs


注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax.WithParameterList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。