本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax.WithModifiers方法的典型用法代码示例。如果您正苦于以下问题:C# FieldDeclarationSyntax.WithModifiers方法的具体用法?C# FieldDeclarationSyntax.WithModifiers怎么用?C# FieldDeclarationSyntax.WithModifiers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax
的用法示例。
在下文中一共展示了FieldDeclarationSyntax.WithModifiers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitFieldDeclaration
public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node)
{
var fieldSymbol = (IFieldSymbol)_model.GetDeclaredSymbol(node.Declaration.Variables[0]);
bool ignored;
if (_unwrittenFields.TryRemove(fieldSymbol, out ignored))
{
return
node.WithModifiers(
node.Modifiers.Add(
SyntaxFactory.Token(
SyntaxFactory.TriviaList(),
SyntaxKind.ReadOnlyKeyword,
SyntaxFactory.TriviaList(
SyntaxFactory.SyntaxTrivia(SyntaxKind.WhitespaceTrivia, " ")))));
}
return node;
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-codeformatter-dotnet,代码行数:18,代码来源:MarkReadonlyFieldsRule.cs
示例2: MakePrivateAsync
/// <summary>
/// Adds the [Tooltip] attribute to the field.
/// </summary>
/// <param name="document">
/// The document containing the field to fix.
/// </param>
/// <param name="fieldDeclaration">
/// The field to fix.
/// </param>
/// <param name="cancellationToken">
/// Details regarding code fix cancellation.
/// </param>
/// <returns>
/// The fixed document.
/// </returns>
private async Task<Document> MakePrivateAsync(Document document, FieldDeclarationSyntax fieldDeclaration, CancellationToken cancellationToken, Diagnostic diagnostic)
{
var publicModifier = fieldDeclaration.Modifiers.FirstOrDefault(m => m.IsKind(SyntaxKind.PublicKeyword));
var privateModifier = SyntaxFactory.Token(SyntaxKind.PrivateKeyword);
var newModifiers = fieldDeclaration.Modifiers.Replace(publicModifier, privateModifier);
var newFieldDeclaration = fieldDeclaration.WithModifiers(newModifiers);
var hasSerializeFieldAttribute = bool.Parse(diagnostic.Properties["hasSerializeFieldAttribute"]);
if (!hasSerializeFieldAttribute)
{
var attribute = SyntaxFactory.Attribute(SyntaxFactory.ParseName("SerializeField"));
var attributeList = SyntaxFactory.AttributeList().AddAttributes(attribute);
var newAttributeLists = fieldDeclaration.AttributeLists.Add(attributeList);
newFieldDeclaration = newFieldDeclaration.WithAttributeLists(newAttributeLists);
}
var root = await document.GetSyntaxRootAsync();
var newRoot = root.ReplaceNode(fieldDeclaration, newFieldDeclaration);
var newDocument = document.WithSyntaxRoot(newRoot);
return newDocument;
}