本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax类的典型用法代码示例。如果您正苦于以下问题:C# FieldDeclarationSyntax类的具体用法?C# FieldDeclarationSyntax怎么用?C# FieldDeclarationSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FieldDeclarationSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了FieldDeclarationSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:joshbtn,项目名称:LINQ-to-Wiki,代码行数:28,代码来源:ModuleGeneratorBase.cs
示例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();
}
开发者ID:OsvaldoJ,项目名称:orchardizer,代码行数:7,代码来源:RoslynExtensions.cs
示例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;
}
开发者ID:chuck-mitchell,项目名称:codeformatter,代码行数:27,代码来源:PrivateFieldNamingRule.CSharp.cs
示例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;
}
开发者ID:asthomas,项目名称:TypescriptSyntaxPaste,代码行数:7,代码来源:FieldDeclarationTranslation.cs
示例5: VisitFieldDeclaration
public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node)
{
if (_fieldsToRemove.Contains(node.GetText().ToString()))
{
return null;
}
return base.VisitFieldDeclaration(node);
}
开发者ID:CNinnovation,项目名称:TechConference2016,代码行数:8,代码来源:RemoveBackingFieldRewriter.cs
示例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();
}
开发者ID:michaelcfanning,项目名称:codeformatter,代码行数:8,代码来源:UnwrittenWritableFieldFixer.cs
示例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)));
}
}
开发者ID:benlaan,项目名称:cs2ts,代码行数:9,代码来源:Transpiler.cs
示例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;
}
开发者ID:nagyistoce,项目名称:code-cracker,代码行数:9,代码来源:ReadonlyFieldCodeFixProvider.cs
示例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;
}
开发者ID:AmadeusW,项目名称:SnippetVS,代码行数:10,代码来源:DiscoveryWalker.cs
示例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);
}
开发者ID:chemix-lunacy,项目名称:Skyling,代码行数:10,代码来源:VariableWalker.cs
示例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());
}
}
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:11,代码来源:WriteField.cs
示例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);
}
开发者ID:haroldhues,项目名称:code-cracker,代码行数:11,代码来源:NoPrivateReadonlyFieldAnalyzer.cs
示例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;
}
开发者ID:itowlson,项目名称:torment-roslyn,代码行数:11,代码来源:CodeFixProvider.cs
示例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;
}
开发者ID:nagyistoce,项目名称:code-cracker,代码行数:12,代码来源:ReadonlyFieldCodeFixProvider.cs
示例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;
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:13,代码来源:PropertyRewriter.cs
示例16: CheckForDiagnostics
private static void CheckForDiagnostics(SyntaxNodeAnalysisContext context, FieldDeclarationSyntax fieldNode, IFieldSymbol fieldSymbol)
{
var isStatic = fieldSymbol.IsStatic;
var isPublic = fieldSymbol.DeclaredAccessibility.HasFlag(Accessibility.Public);
var isReadOnly = fieldSymbol.IsReadOnly;
if (!isStatic || !isPublic || !isReadOnly)
{
context.ReportDiagnostic(Diagnostic.Create(
EvaluateManagedBackingFieldsAnalayzer.mustBePublicStaticAndReadonlyRule,
fieldNode.GetLocation()));
}
}
开发者ID:ronnymgm,项目名称:csla-light,代码行数:13,代码来源:EvaluateManagedBackingFieldsAnalayzer.cs
示例17: MakePrivateDeclarationAsync
private async Task<Document> MakePrivateDeclarationAsync(Document document, FieldDeclarationSyntax declaration, CancellationToken c)
{
var accessToken = declaration.ChildTokens()
.SingleOrDefault(token => token.Kind() == SyntaxKind.PublicKeyword);
var privateAccessToken = SyntaxFactory.Token(SyntaxKind.PrivateKeyword);
var root = await document.GetSyntaxRootAsync(c);
var newRoot = root.ReplaceToken(accessToken, privateAccessToken);
return document.WithSyntaxRoot(newRoot);
}
开发者ID:Winsto,项目名称:MVA-Roslyn,代码行数:13,代码来源:CodeFixProvider.cs
示例18: MakePrivateAsync
private async Task<Document> MakePrivateAsync(Document document, FieldDeclarationSyntax fieldDeclaration, CancellationToken cancellationToken) {
SyntaxToken privateSyntaxToken = CreatePrivateSyntaxToken(fieldDeclaration);
IEnumerable<SyntaxToken> newFieldModifiers = new[] { privateSyntaxToken }.Union(
fieldDeclaration.Modifiers.Where(modifier =>
modifier.Kind() != SyntaxKind.InternalKeyword && modifier.Kind() != SyntaxKind.PublicKeyword)
.Select(modifier => modifier.WithLeadingTrivia()));
FieldDeclarationSyntax newfieldDeclaration = fieldDeclaration.Update(fieldDeclaration.AttributeLists,
new SyntaxTokenList().AddRange(newFieldModifiers),
fieldDeclaration.Declaration.WithoutTrivia(),
fieldDeclaration.SemicolonToken)
.WithLeadingTrivia(fieldDeclaration.GetLeadingTrivia())
.WithTrailingTrivia(fieldDeclaration.GetTrailingTrivia());
return await this.ReplaceNodeInDocumentAsync(document, cancellationToken, fieldDeclaration, newfieldDeclaration);
}
开发者ID:vuder,项目名称:CodingStandardCodeAnalyzers,代码行数:16,代码来源:FieldAccessCodeAnalyzerCodeFixProvider.cs
示例19: LastField
private static MemberDeclarationSyntax LastField(
SyntaxList<MemberDeclarationSyntax> members,
FieldDeclarationSyntax fieldDeclaration)
{
var lastConst = members.AsEnumerable()
.OfType<FieldDeclarationSyntax>()
.Where(f => f.Modifiers.Any(SyntaxKind.ConstKeyword)).LastOrDefault();
// Place a const after the last existing const.
if (fieldDeclaration.Modifiers.Any(SyntaxKind.ConstKeyword))
{
return lastConst;
}
// Place a field after the last field, or after the last const.
return LastField(members) ?? lastConst;
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:17,代码来源:FieldGenerator.cs
示例20: NeedsRewrite
private static bool NeedsRewrite(FieldDeclarationSyntax fieldSyntax, out bool isInstance)
{
if (!IsPrivateField(fieldSyntax, out isInstance))
{
return false;
}
foreach (var v in fieldSyntax.Declaration.Variables)
{
if (!IsGoodPrivateFieldName(v.Identifier.ValueText, isInstance))
{
return true;
}
}
return false;
}
开发者ID:chuck-mitchell,项目名称:codeformatter,代码行数:17,代码来源:PrivateFieldNamingRule.CSharp.cs
注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论