本文整理汇总了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);
}
示例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);
}
示例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);
}