本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax.WithDeclaration方法的典型用法代码示例。如果您正苦于以下问题:C# FieldDeclarationSyntax.WithDeclaration方法的具体用法?C# FieldDeclarationSyntax.WithDeclaration怎么用?C# FieldDeclarationSyntax.WithDeclaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax
的用法示例。
在下文中一共展示了FieldDeclarationSyntax.WithDeclaration方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeMultipleFieldsReadonly
private static SyntaxNode MakeMultipleFieldsReadonly(SyntaxNode root, FieldDeclarationSyntax fieldDeclaration, VariableDeclaratorSyntax variableToMakeReadonly)
{
var newDeclaration = fieldDeclaration.Declaration.RemoveNode(variableToMakeReadonly, SyntaxRemoveOptions.KeepEndOfLine);
var newFieldDeclaration = fieldDeclaration.WithDeclaration(newDeclaration);
var newReadonlyFieldDeclaration = fieldDeclaration.WithDeclaration(SyntaxFactory.VariableDeclaration(fieldDeclaration.Declaration.Type, SyntaxFactory.SeparatedList(new[] { variableToMakeReadonly })))
.WithoutLeadingTrivia()
.WithTrailingTrivia(SyntaxFactory.ParseTrailingTrivia("\n"))
.AddModifiers(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword))
.WithAdditionalAnnotations(Formatter.Annotation);
var newRoot = root.ReplaceNode(fieldDeclaration, new[] { newFieldDeclaration, newReadonlyFieldDeclaration });
return newRoot;
}
示例2: VisitFieldDeclaration
public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node)
{
bool isInstance;
if (NeedsRewrite(node, out isInstance))
{
var list = new List<VariableDeclaratorSyntax>(node.Declaration.Variables.Count);
foreach (var v in node.Declaration.Variables)
{
if (IsGoodPrivateFieldName(v.Identifier.Text, isInstance))
{
list.Add(v);
}
else
{
list.Add(v.WithAdditionalAnnotations(s_markerAnnotation));
_count++;
}
}
var declaration = node.Declaration.WithVariables(SyntaxFactory.SeparatedList(list));
node = node.WithDeclaration(declaration);
return node;
}
return node;
}
示例3: HandleFieldDeclaration
private static SyntaxNode HandleFieldDeclaration(FieldDeclarationSyntax node)
{
VariableDeclarationSyntax declaration = node.Declaration;
if (declaration == null || declaration.IsMissing)
{
return null;
}
SyntaxTokenList modifiers = DeclarationModifiersHelper.AddModifier(node.Modifiers, ref declaration, SyntaxKind.PrivateKeyword);
return node
.WithDeclaration(declaration)
.WithModifiers(modifiers)
.WithoutFormatting();
}
示例4: VisitFieldDeclaration
public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node)
{
node = node.WithDeclaration((VariableDeclarationSyntax)VisitVariableDeclaration(node.Declaration));
if (node.Declaration.Variables.Count == 1)
{
string typeName = node.Declaration.Type.ToString();
switch (typeName)
{
case "typedef":
{
Debug.Assert(pending_ == null);
pending_ = new ResolveTypedef(node, ctx_);
return null;
}
case "property":
{
var variable = node.Declaration.Variables[0];
var initializer = variable.Initializer;
if (initializer != null)
{
var propType = Compiler.ConstantType(initializer.Value);
var result = Compiler.Property(propType, variable.Identifier);
return result;
}
return node;
}
}
string variableName = node.Declaration.Variables[0].Identifier.ToString();
switch (variableName)
{
case "function":
case "method":
{
//when functions are declared with types the parser generates
//a subsquent erroneous method declaration
Debug.Assert(pending_ == null);
pending_ = new ResolveTypedFunction(node, ctx_, variableName == "method");
return null;
}
case "property":
{
//when functions are declared with types the parser generates
//a subsquent erroneous method declaration
Debug.Assert(pending_ == null);
var result = Compiler.Property(node.Declaration.Type);
pending_ = new ResolveProperty(result);
return null;
}
}
}
return node;
}
示例5: RemoveField
private static SyntaxNode RemoveField(SyntaxNode root, VariableDeclaratorSyntax variableDeclarator, FieldDeclarationSyntax fieldDeclaration)
{
var currentField = root.GetCurrentNode(fieldDeclaration);
var multipleVariableDeclaration = fieldDeclaration.Declaration.Variables.Count > 1;
root = multipleVariableDeclaration
? root.ReplaceNode(currentField, fieldDeclaration
.WithDeclaration(fieldDeclaration.Declaration.RemoveNode(variableDeclarator, SyntaxRemoveOptions.KeepNoTrivia)))
: root.RemoveNode(currentField, SyntaxRemoveOptions.KeepNoTrivia);
return root;
}