本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax类的典型用法代码示例。如果您正苦于以下问题:C# FieldDeclarationSyntax类的具体用法?C# FieldDeclarationSyntax怎么用?C# FieldDeclarationSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FieldDeclarationSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了FieldDeclarationSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePropertiesField
/// <summary>
/// Creates a field that holds <see cref="QueryTypeProperties{T}"/> for the module.
/// </summary>
protected FieldDeclarationSyntax CreatePropertiesField(
Module module, string resultClassName, FieldDeclarationSyntax propsField, SortType? sortType)
{
var queryTypePropertiesType = SyntaxEx.GenericName("QueryTypeProperties", resultClassName);
var propertiesInitializer = SyntaxEx.ObjectCreation(
queryTypePropertiesType,
SyntaxEx.Literal(module.Name),
SyntaxEx.Literal(module.Prefix),
module.QueryType == null
? (ExpressionSyntax)SyntaxEx.NullLiteral()
: SyntaxEx.MemberAccess("QueryType", module.QueryType.ToString()),
sortType == null
? (ExpressionSyntax)SyntaxEx.NullLiteral()
: SyntaxEx.MemberAccess("SortType", sortType.ToString()),
CreateTupleListExpression(GetBaseParameters(module)),
propsField == null ? (ExpressionSyntax)SyntaxEx.NullLiteral() : (NamedNode)propsField,
resultClassName == "object"
? (ExpressionSyntax)SyntaxEx.LambdaExpression("_", SyntaxEx.NullLiteral())
: SyntaxEx.MemberAccess(resultClassName, "Parse"));
return SyntaxEx.FieldDeclaration(
new[] { SyntaxKind.PrivateKeyword, SyntaxKind.StaticKeyword, SyntaxKind.ReadOnlyKeyword },
queryTypePropertiesType, ClassNameBase + "Properties", propertiesInitializer);
}
示例2: GetFieldName
public static string GetFieldName(FieldDeclarationSyntax field)
{
var variable = field.Declaration.Variables.FirstOrDefault(); //.DescendantNodes().Where(e => e.IsKind(SyntaxKind.IdentifierToken)).Last().Span.ToString();
if (variable == null)
return "";
return variable.Identifier.ToString();
}
示例3: 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;
}
示例4: FieldDeclarationTranslation
public FieldDeclarationTranslation(FieldDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
{
Declaration = syntax.Declaration.Get<VariableDeclarationTranslation>(this);
Declaration.ExcludeVar = true;
Modifiers = syntax.Modifiers.Get(this);
Modifiers.ConstantToStatic = true;
}
示例5: VisitFieldDeclaration
public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node)
{
if (_fieldsToRemove.Contains(node.GetText().ToString()))
{
return null;
}
return base.VisitFieldDeclaration(node);
}
示例6: AddReadonlyModifier
private async Task<Document> AddReadonlyModifier(Document document, SyntaxNode root, FieldDeclarationSyntax fieldDeclaration, CancellationToken cancellationToken)
{
var docEditor = await DocumentEditor.CreateAsync(document, cancellationToken).ConfigureAwait(false);
var modifiers = docEditor.Generator.GetModifiers(fieldDeclaration);
docEditor.SetModifiers(fieldDeclaration, modifiers + DeclarationModifiers.ReadOnly);
return docEditor.GetChangedDocument();
}
示例7: VisitFieldDeclaration
public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
{
string visibility = GetVisibilityModifier(node.Modifiers);
foreach (var identifier in node.Declaration.Variables)
{
Emit(string.Format("{0} {1}: {2};", visibility, identifier.GetText(), GetMappedType(node.Declaration.Type)));
}
}
示例8: MakeSingleFieldReadonly
private static SyntaxNode MakeSingleFieldReadonly(SyntaxNode root, FieldDeclarationSyntax fieldDeclaration)
{
var newFieldDeclaration = fieldDeclaration.AddModifiers(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword))
.WithTrailingTrivia(fieldDeclaration.GetTrailingTrivia())
.WithLeadingTrivia(fieldDeclaration.GetLeadingTrivia())
.WithAdditionalAnnotations(Formatter.Annotation);
var newRoot = root.ReplaceNode(fieldDeclaration, newFieldDeclaration);
return newRoot;
}
示例9: VisitFieldDeclaration
public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
{
base.VisitFieldDeclaration(node);
foreach (var variable in node.Declaration.Variables)
{
var test = variable.Identifier;
DefinedOutside.Add(variable.Identifier.ToString(), variable.ToFullString());
}
var t = DefinedOutside;
}
示例10: VisitFieldDeclaration
public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
{
string type = node.Declaration.Type.ToString();
foreach (Variable var in node.Declaration.Variables.Select(val => new Variable() { Name = val.Identifier.ToString(), Type = type }))
{
this.Variables.Add(var);
}
base.VisitFieldDeclaration(node);
}
示例11: Go
public static void Go(OutputWriter writer, FieldDeclarationSyntax field)
{
foreach (var declaration in field.Declaration.Variables)
{
//TODO: Add support for threadstatic
Go(writer, field, field.Modifiers,
WriteIdentifierName.TransformIdentifier(declaration.Identifier.Text), field.Declaration.Type,
declaration.Initializer,field.IsThreadStatic());
}
}
示例12: CaptureCandidateFields
private static void CaptureCandidateFields(FieldDeclarationSyntax field, SemanticModel semanticModel, List<FieldCandidate> candidateFields)
{
if (!CanBecameReadOnlyField(field)) return;
var variables = field.Declaration.Variables;
var currentAnalysisCandidateFields = variables.Select(s => new FieldCandidate { Variable = s, FieldSymbol = semanticModel.GetDeclaredSymbol(s) as IFieldSymbol })
.Where(p => p.FieldSymbol != null && p.FieldSymbol.ContainingType != null);
if (!currentAnalysisCandidateFields.Any()) return;
candidateFields.AddRange(currentAnalysisCandidateFields);
}
示例13: MakeReadOnlyAsync
private async Task<Document> MakeReadOnlyAsync(Document document, FieldDeclarationSyntax fieldDecl, CancellationToken cancellationToken)
{
var roKeyword = SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword);
var roFieldDecl = fieldDecl.AddModifiers(roKeyword);
var root = await document.GetSyntaxRootAsync(cancellationToken);
var newRoot = root.ReplaceNode(fieldDecl, roFieldDecl);
var newDocument = document.WithSyntaxRoot(newRoot);
return newDocument;
}
示例14: 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;
}
示例15: VisitFieldDeclaration
public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax field)
{
// Retrieve the symbol for the field's variable
if (field.Declaration.Variables.Count == 1)
{
if (object.Equals(semanticModel.GetDeclaredSymbol(field.Declaration.Variables.First()), backingField))
{
return null;
}
}
return field;
}