本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxList类的典型用法代码示例。如果您正苦于以下问题:C# SyntaxList类的具体用法?C# SyntaxList怎么用?C# SyntaxList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SyntaxList类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了SyntaxList类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: VisitBlock
public override SyntaxNode VisitBlock(BlockSyntax node)
{
BlockSyntax block = (BlockSyntax)base.VisitBlock(node);
SyntaxList<StatementSyntax> curList = new SyntaxList<StatementSyntax>();
Dictionary<string, SyntaxNode> replacements = new Dictionary<string, SyntaxNode>();
int numbering = 1;
foreach (var stmt in block.Statements)
{
SyntaxList<StatementSyntax> preList = new SyntaxList<StatementSyntax>();
var stm = stmt.ReplaceNodes(nodes: stmt.DescendantNodes().Reverse(), computeReplacementNode: (original, origWithReplacedDesc) =>
{
Console.WriteLine(origWithReplacedDesc.GetType() + ": " + origWithReplacedDesc);
if (origWithReplacedDesc.IsKind(SyntaxKind.InvocationExpression)
|| origWithReplacedDesc.IsKind(SyntaxKind.ObjectCreationExpression))
{
return SimplifyMethodAndConstructorInvocation(ref numbering, ref preList, original, origWithReplacedDesc);
}
return origWithReplacedDesc;
});
curList = curList.AddRange(preList);
curList = curList.Add(stm);
}
return block.WithStatements(curList);
}
开发者ID:TubaKayaDev,项目名称:Call-Graph-Builder-DotNet,代码行数:26,代码来源:MethodSimpifier.cs
示例2: ComputeFixesAsync
public sealed override async Task ComputeFixesAsync(CodeFixContext context)
{
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
var diagnostic = context.Diagnostics.First();
var diagnosticSpan = diagnostic.Location.SourceSpan;
var token = root.FindToken(diagnosticSpan.Start);
if (token.IsKind(SyntaxKind.CatchKeyword))
{
var catchBlock = (CatchClauseSyntax)token.Parent;
var tryStmt = (TryStatementSyntax)catchBlock.Parent;
var throwStatement = SyntaxFactory.ThrowStatement();
var newStatements = new SyntaxList<StatementSyntax>().Add(throwStatement);
var newBlock = SyntaxFactory.Block().WithStatements(newStatements);
var newCatchBlock = SyntaxFactory.CatchClause().WithBlock(newBlock).WithAdditionalAnnotations(Formatter.Annotation);
var newRoot = root.ReplaceNode(catchBlock, newCatchBlock);
context.RegisterFix(
CodeAction.Create("throw", context.Document.WithSyntaxRoot(newRoot)),
diagnostic);
}
}
开发者ID:julid29,项目名称:confsamples,代码行数:26,代码来源:CodeFixProvider.cs
示例3: MultiLineElement
public static XmlElementSyntax MultiLineElement(XmlNameSyntax name, string newLineText, SyntaxList<XmlNodeSyntax> content)
{
return SyntaxFactory.XmlElement(
SyntaxFactory.XmlElementStartTag(name),
content.Insert(0, NewLine(newLineText)).Add(NewLine(newLineText)),
SyntaxFactory.XmlElementEndTag(name));
}
开发者ID:nvincent,项目名称:StyleCopAnalyzers,代码行数:7,代码来源:XmlSyntaxFactory.cs
示例4: MethodDeclaration
public static MethodDeclarationSyntax MethodDeclaration(
SyntaxList<AttributeListSyntax> attributeLists,
SyntaxTokenList modifiers,
TypeSyntax returnType,
ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier,
SyntaxToken identifier,
TypeParameterListSyntax typeParameterList,
ParameterListSyntax parameterList,
SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
BlockSyntax body,
SyntaxToken semicolonToken)
{
return SyntaxFactory.MethodDeclaration(
attributeLists,
modifiers,
default(SyntaxToken),
returnType,
explicitInterfaceSpecifier,
identifier,
typeParameterList,
parameterList,
constraintClauses,
body,
default(ArrowExpressionClauseSyntax),
semicolonToken);
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:26,代码来源:MethodDeclarationSyntax.cs
示例5: CheckUsingDeclarations
private static void CheckUsingDeclarations(SyntaxNodeAnalysisContext context, SyntaxList<UsingDirectiveSyntax> usingDirectives)
{
UsingDirectiveSyntax lastStaticUsingDirective = null;
foreach (var usingDirective in usingDirectives)
{
if (usingDirective.IsPrecededByPreprocessorDirective())
{
lastStaticUsingDirective = null;
}
if (usingDirective.StaticKeyword.IsKind(SyntaxKind.StaticKeyword))
{
if (lastStaticUsingDirective != null)
{
var firstName = lastStaticUsingDirective.Name.ToNormalizedString();
var secondName = usingDirective.Name.ToNormalizedString();
if (CultureInfo.InvariantCulture.CompareInfo.Compare(firstName, secondName, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreWidth) > 0)
{
context.ReportDiagnostic(Diagnostic.Create(Descriptor, lastStaticUsingDirective.GetLocation(), new[] { firstName, secondName }));
return;
}
}
lastStaticUsingDirective = usingDirective;
}
}
}
开发者ID:EdwinEngelen,项目名称:StyleCopAnalyzers,代码行数:29,代码来源:SA1217UsingStaticDirectivesMustBeOrderedAlphabetically.cs
示例6: TryGetThreadStaticAttribute
private static bool TryGetThreadStaticAttribute(SyntaxList<AttributeListSyntax> attributeLists, SemanticModel semanticModel, out AttributeSyntax threadStaticAttribute)
{
threadStaticAttribute = null;
if (!attributeLists.Any())
{
return false;
}
foreach (var attributeList in attributeLists)
{
foreach (var attribute in attributeList.Attributes)
{
var attributeType = semanticModel.GetTypeInfo(attribute).Type;
if (attributeType != null &&
attributeType.ToDisplayString() == ThreadStaticAttributeName)
{
threadStaticAttribute = attribute;
return true;
}
}
}
return false;
}
开发者ID:ozgurkayaist,项目名称:sonarlint-vs,代码行数:26,代码来源:ThreadStaticNonStaticField.cs
示例7: Element
public static XmlElementSyntax Element(XmlNameSyntax name, SyntaxList<XmlNodeSyntax> content)
{
return SyntaxFactory.XmlElement(
SyntaxFactory.XmlElementStartTag(name),
content,
SyntaxFactory.XmlElementEndTag(name));
}
开发者ID:nvincent,项目名称:StyleCopAnalyzers,代码行数:7,代码来源:XmlSyntaxFactory.cs
示例8: ProcessUsings
private static void ProcessUsings(SyntaxNodeAnalysisContext context, SyntaxList<UsingDirectiveSyntax> usings)
{
var usingDirectives = new List<UsingDirectiveSyntax>();
var systemUsingDirectives = new List<UsingDirectiveSyntax>();
foreach (var usingDirective in usings)
{
if (IsAliasOrStaticUsingDirective(usingDirective))
{
continue;
}
if (usingDirective.IsPrecededByPreprocessorDirective())
{
CheckIncorrectlyOrderedUsingsAndReportDiagnostic(context, usingDirectives);
CheckIncorrectlyOrderedUsingsAndReportDiagnostic(context, systemUsingDirectives);
usingDirectives.Clear();
systemUsingDirectives.Clear();
}
if (HasNamespaceAliasQualifier(usingDirective) || !usingDirective.IsSystemUsingDirective())
{
usingDirectives.Add(usingDirective);
}
else
{
systemUsingDirectives.Add(usingDirective);
}
}
CheckIncorrectlyOrderedUsingsAndReportDiagnostic(context, usingDirectives);
CheckIncorrectlyOrderedUsingsAndReportDiagnostic(context, systemUsingDirectives);
}
开发者ID:nvincent,项目名称:StyleCopAnalyzers,代码行数:33,代码来源:SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace.cs
示例9: ProcessUsingsAndReportDiagnostic
private static void ProcessUsingsAndReportDiagnostic(SyntaxList<UsingDirectiveSyntax> usings, SyntaxNodeAnalysisContext context)
{
string systemUsingDirectivesShouldBeBeforeThisName = null;
for (var i = 1; i < usings.Count; i++)
{
var usingDirective = usings[i];
if (usingDirective.Alias != null || !usingDirective.StaticKeyword.IsKind(SyntaxKind.None) || usingDirective.IsPrecededByPreprocessorDirective())
{
continue;
}
if (usingDirective.IsSystemUsingDirective())
{
if (systemUsingDirectivesShouldBeBeforeThisName != null)
{
context.ReportDiagnostic(Diagnostic.Create(Descriptor, usingDirective.GetLocation(), usingDirective.Name.ToNormalizedString(), systemUsingDirectivesShouldBeBeforeThisName));
continue;
}
var previousUsing = usings[i - 1];
if (!previousUsing.IsSystemUsingDirective() || previousUsing.StaticKeyword.Kind() != SyntaxKind.None)
{
systemUsingDirectivesShouldBeBeforeThisName = previousUsing.Name.ToNormalizedString();
context.ReportDiagnostic(Diagnostic.Create(Descriptor, usingDirective.GetLocation(), usingDirective.Name.ToNormalizedString(), systemUsingDirectivesShouldBeBeforeThisName));
}
}
}
}
开发者ID:hvanbakel,项目名称:StyleCopAnalyzers,代码行数:30,代码来源:SA1208SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives.cs
示例10: Sort
internal static SyntaxList<UsingDirectiveSyntax> Sort(SyntaxList<UsingDirectiveSyntax> directives) =>
SyntaxFactory.List(
directives.
OrderBy(x => x.StaticKeyword.IsKind(SyntaxKind.StaticKeyword) ? 1 : x.Alias == null ? 0 : 2).
ThenBy(x => x.Alias?.ToString()).
ThenBy(x => x.Name.ToString())
.Distinct(new AutoRest.Core.Utilities.EqualityComparer<UsingDirectiveSyntax>((a, b) => a.Name.ToString() == b.Name.ToString(), a=> 0 )));
开发者ID:devigned,项目名称:autorest,代码行数:7,代码来源:AddUsingsRewriter.cs
示例11: MakeInterfaceSyntaxList
private static SyntaxList<MemberDeclarationSyntax> MakeInterfaceSyntaxList(IEnumerable<MemberDeclarationSyntax> members)
{
var newMembers = ExtractInterfaceMembers(members).ToArray();
var syntaxList = new SyntaxList<MemberDeclarationSyntax>();
syntaxList = syntaxList.AddRange(newMembers);
return syntaxList;
}
开发者ID:asthomas,项目名称:TypescriptSyntaxPaste,代码行数:7,代码来源:ClassToInterfaceReplacement.cs
示例12: ComputeRefactoringsAsync
public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var document = context.Document;
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
return;
var span = context.Span;
if (!span.IsEmpty)
return;
var cancellationToken = context.CancellationToken;
if (cancellationToken.IsCancellationRequested)
return;
var model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
if (model.IsFromGeneratedCode(cancellationToken))
return;
var root = await model.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);
var token = root.FindToken(span.Start);
var parameter = token.Parent as ParameterSyntax;
if (parameter != null)
{
var ctor = parameter.Parent.Parent as ConstructorDeclarationSyntax;
if (ctor == null)
return;
context.RegisterRefactoring(
CodeActionFactory.Create(
parameter.Span,
DiagnosticSeverity.Info,
GettextCatalog.GetString("Initialize auto-property from parameter"),
t2 =>
{
var propertyName = GetPropertyName(parameter.Identifier.ToString());
var accessorDeclList = new SyntaxList<AccessorDeclarationSyntax>().Add(SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))).Add(SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)));
var newProperty = SyntaxFactory.PropertyDeclaration(parameter.Type, propertyName)
.WithAccessorList(SyntaxFactory.AccessorList(accessorDeclList))
.WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)))
.WithAdditionalAnnotations(Formatter.Annotation);
var assignmentStatement = SyntaxFactory.ExpressionStatement(
SyntaxFactory.AssignmentExpression(
SyntaxKind.SimpleAssignmentExpression,
propertyName != parameter.Identifier.ToString() ? (ExpressionSyntax)SyntaxFactory.IdentifierName(propertyName) : SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ThisExpression(), SyntaxFactory.IdentifierName(parameter.Identifier)),
SyntaxFactory.IdentifierName(parameter.Identifier)
)
).WithAdditionalAnnotations(Formatter.Annotation);
root = root.TrackNodes(ctor);
var newRoot = root.InsertNodesBefore(root.GetCurrentNode(ctor), new List<SyntaxNode>() {
newProperty
});
newRoot = newRoot.ReplaceNode(newRoot.GetCurrentNode(ctor), ctor.WithBody(
ctor.Body.WithStatements(SyntaxFactory.List<StatementSyntax>(new[] { assignmentStatement }.Concat(ctor.Body.Statements)))
));
return Task.FromResult(document.WithSyntaxRoot(newRoot));
})
);
}
}
开发者ID:Kavignon,项目名称:RefactoringEssentials,代码行数:59,代码来源:InitializeAutoPropertyFromConstructorParameterCodeRefactoringProvider.cs
示例13: TrouverAssignations
/// <summary>
/// Retourne les assignations dans une listes d'expressions.
/// </summary>
/// <param name="expressions">Liste d'expressions.</param>
/// <param name="modèleSémantique">Modèle sémantique.</param>
/// <returns>La liste d'assignations.</returns>
public static IEnumerable<StatementSyntax> TrouverAssignations(SyntaxList<StatementSyntax> expressions, SemanticModel modèleSémantique) =>
expressions.Where(e =>
{
var expression = (e as ExpressionStatementSyntax)?.Expression as AssignmentExpressionSyntax;
return expression?.Kind() == SyntaxKind.SimpleAssignmentExpression
&& modèleSémantique.GetSymbolInfo(expression.Left).Symbol?.Kind == SymbolKind.Field
&& modèleSémantique.GetSymbolInfo(expression.Right).Symbol?.Kind == SymbolKind.Parameter;
});
开发者ID:JabX,项目名称:controle-point-virgule,代码行数:14,代码来源:Partagé.cs
示例14: caseStatement
private static StatementSyntax caseStatement(SyntaxList<StatementSyntax> statements)
{
Debug.Assert(statements.Any());
if (statements.Count == 1)
return statements.First();
return CSharp.Block(statements);
}
开发者ID:mpmedia,项目名称:Excess,代码行数:9,代码来源:Match.cs
示例15: AttributeListList
public static SyntaxList<AttributeListSyntax> AttributeListList(params AttributeSyntax[] attributes)
{
var list = new SyntaxList<AttributeListSyntax>();
foreach (AttributeSyntax attributeSyntax in attributes)
{
list = list.Add(AttributeList(attributeSyntax));
}
return list;
}
开发者ID:cdsalmons,项目名称:OrleansTemplates,代码行数:9,代码来源:AttributeUtils.cs
示例16: CreateSection
private static SwitchSectionSyntax CreateSection(SwitchLabelSyntax label, StatementSyntax statement)
{
var labels = new SyntaxList<SwitchLabelSyntax>();
labels = labels.Add(label);
return SyntaxFactory.SwitchSection(
labels, CreateSectionStatements(statement)
);
}
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:9,代码来源:ConvertToSwitchCodeFixProvider.cs
示例17: CreateAutoProperty
internal static PropertyDeclarationSyntax CreateAutoProperty(TypeSyntax type, string identifier, SyntaxList<AccessorDeclarationSyntax> accessors, SyntaxKind? accessibility)
{
var newProperty = SyntaxFactory.PropertyDeclaration(type, identifier)
.WithAccessorList(SyntaxFactory.AccessorList(accessors));
if (accessibility.HasValue)
newProperty = newProperty.WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(accessibility.Value)));
return newProperty.WithAdditionalAnnotations(Formatter.Annotation);
}
开发者ID:ceddlyburge,项目名称:RefactoringEssentials,代码行数:10,代码来源:Manipulations.cs
示例18: HasThreadStaticAttribute
private static bool HasThreadStaticAttribute(SyntaxList<AttributeListSyntax> attributeLists, SemanticModel semanticModel)
{
if (!attributeLists.Any())
{
return false;
}
return attributeLists.Any(attributeList =>
attributeList.Attributes.Any(attribute => semanticModel.GetTypeInfo(attribute).Type.Is(KnownType.System_ThreadStaticAttribute)));
}
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:10,代码来源:ThreadStaticWithInitializer.cs
示例19: Organize
public static void Organize(
SyntaxList<ExternAliasDirectiveSyntax> externAliasList,
SyntaxList<UsingDirectiveSyntax> usingList,
bool placeSystemNamespaceFirst,
out SyntaxList<ExternAliasDirectiveSyntax> organizedExternAliasList,
out SyntaxList<UsingDirectiveSyntax> organizedUsingList)
{
if (externAliasList.Count > 0 || usingList.Count > 0)
{
// Merge the list of usings and externs into one list.
// order them in the order that they were originally in the
// file.
var initialList = usingList.Cast<SyntaxNode>()
.Concat(externAliasList)
.OrderBy(n => n.SpanStart).ToList();
if (!initialList.SpansPreprocessorDirective())
{
// If there is a banner comment that precedes the nodes,
// then remove it and store it for later.
IEnumerable<SyntaxTrivia> leadingTrivia;
initialList[0] = initialList[0].GetNodeWithoutLeadingBannerAndPreprocessorDirectives(out leadingTrivia);
var comparer = placeSystemNamespaceFirst
? UsingsAndExternAliasesDirectiveComparer.SystemFirstInstance
: UsingsAndExternAliasesDirectiveComparer.NormalInstance;
var finalList = initialList.OrderBy(comparer).ToList();
// Check if sorting the list actually changed anything. If not, then we don't
// need to make any changes to the file.
if (!finalList.SequenceEqual(initialList))
{
// Make sure newlines are correct between nodes.
EnsureNewLines(finalList);
// Reattach the banner.
finalList[0] = finalList[0].WithPrependedLeadingTrivia(leadingTrivia);
// Now split out the externs and usings back into two separate lists.
organizedExternAliasList = finalList.Where(t => t is ExternAliasDirectiveSyntax)
.Cast<ExternAliasDirectiveSyntax>()
.ToSyntaxList();
organizedUsingList = finalList.Where(t => t is UsingDirectiveSyntax)
.Cast<UsingDirectiveSyntax>()
.ToSyntaxList();
return;
}
}
}
organizedExternAliasList = externAliasList;
organizedUsingList = usingList;
}
开发者ID:otawfik-ms,项目名称:roslyn,代码行数:54,代码来源:UsingsAndExternAliasesOrganizer.cs
示例20: ExtractMembersFromClass
private static Dictionary<string, string> ExtractMembersFromClass(SyntaxList<MemberDeclarationSyntax> classMembers)
{
var members = new Dictionary<string, string>();
foreach (var m in classMembers)
{
var name = "";
if (m.IsKind(SyntaxKind.MethodDeclaration))
{
var eve = m as MethodDeclarationSyntax;
name = eve.Identifier.Text;
}
if (m.IsKind(SyntaxKind.EventDeclaration))
{
var theEvent = m as EventDeclarationSyntax;
name = theEvent.Identifier.Text;
}
if (m.IsKind(SyntaxKind.EventFieldDeclaration))
{
var eventField = m as EventFieldDeclarationSyntax;
foreach (var v in eventField.Declaration.Variables)
{
members.Add(v.Identifier.Text, eventField.Declaration.Type.ToString());
}
}
if (m.IsKind(SyntaxKind.FieldDeclaration))
{
var field = m as FieldDeclarationSyntax;
foreach (var v in field.Declaration.Variables)
{
members.Add(v.Identifier.Text, field.Declaration.Type.ToString());
}
}
if (m.IsKind(SyntaxKind.PropertyDeclaration))
{
var property = m as PropertyDeclarationSyntax;
name = property.Identifier.Text;
}
if (m.IsKind(SyntaxKind.DelegateDeclaration))
{
var theDelegate = m as DelegateDeclarationSyntax;
name = theDelegate.Identifier.Text;
}
if (m.IsKind(SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKind.EnumDeclaration, SyntaxKind.InterfaceDeclaration))
{
var type = m as BaseTypeDeclarationSyntax;
name = type.Identifier.Text;
}
if (name != "")
{
members.Add(name, "");
}
}
return members;
}
开发者ID:Vossekop,项目名称:code-cracker,代码行数:54,代码来源:IntroduceFieldFromConstructorCodeFixProvider.cs
注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxList类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论