本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxList.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxList.AddRange方法的具体用法?C# SyntaxList.AddRange怎么用?C# SyntaxList.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxList
的用法示例。
在下文中一共展示了SyntaxList.AddRange方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: DoTestAddInsertRemoveReplaceOnEmptyList
private void DoTestAddInsertRemoveReplaceOnEmptyList(SyntaxList<SyntaxNode> list)
{
Assert.Equal(0, list.Count);
SyntaxNode nodeD = SyntaxFactory.ParseExpression("D ");
SyntaxNode nodeE = SyntaxFactory.ParseExpression("E ");
var newList = list.Add(nodeD);
Assert.Equal(1, newList.Count);
Assert.Equal("D ", newList.ToFullString());
newList = list.AddRange(new[] { nodeD, nodeE });
Assert.Equal(2, newList.Count);
Assert.Equal("D E ", newList.ToFullString());
newList = list.Insert(0, nodeD);
Assert.Equal(1, newList.Count);
Assert.Equal("D ", newList.ToFullString());
newList = list.InsertRange(0, new[] { nodeD, nodeE });
Assert.Equal(2, newList.Count);
Assert.Equal("D E ", newList.ToFullString());
newList = list.Remove(nodeD);
Assert.Equal(0, newList.Count);
Assert.Equal(-1, list.IndexOf(nodeD));
Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(0));
Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(1, nodeD));
Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(-1, nodeD));
Assert.Throws<ArgumentOutOfRangeException>(() => list.InsertRange(1, new[] { nodeD }));
Assert.Throws<ArgumentOutOfRangeException>(() => list.InsertRange(-1, new[] { nodeD }));
Assert.Throws<ArgumentException>(() => list.Replace(nodeD, nodeE));
Assert.Throws<ArgumentException>(() => list.ReplaceRange(nodeD, new[] { nodeE }));
Assert.Throws<ArgumentNullException>(() => list.Add(null));
Assert.Throws<ArgumentNullException>(() => list.AddRange((IEnumerable<SyntaxNode>)null));
Assert.Throws<ArgumentNullException>(() => list.Insert(0, null));
Assert.Throws<ArgumentNullException>(() => list.InsertRange(0, (IEnumerable<SyntaxNode>)null));
}
示例4: AddLambdaThis
private SyntaxNode AddLambdaThis(SyntaxNode node)
{
//SyntaxTreeHelper.PrintTree(node);
if (!node.GetAnnotations("haslambdas").Any())
{
return node;
}
/*if (!node.DescendantNodes().OfType<ParenthesizedLambdaExpressionSyntax>().Any())
{
return node;
}*/
var stmt = CreateLambdaThis();
var stmtlist = new SyntaxList<StatementSyntax>();
stmtlist = stmtlist.Add(stmt);
stmtlist = stmtlist.AddRange(node.ChildNodes().OfType<StatementSyntax>());
node = SyntaxFactory.Block(stmtlist);
return node;
}
示例5: CreateSectionStatements
private static SyntaxList<StatementSyntax> CreateSectionStatements(StatementSyntax source)
{
var result = new SyntaxList<StatementSyntax>();
if (source is BlockSyntax)
{
var block = source as BlockSyntax;
result = result.AddRange(block.Statements);
}
else
{
result = result.Add(source);
}
var lastStatement = result.LastOrDefault();
if (!(lastStatement is ReturnStatementSyntax || lastStatement is ThrowStatementSyntax))
{
result = result.Add(SyntaxFactory.BreakStatement());
}
return result;
}
示例6: MakeInterfaceProperty
private static PropertyDeclarationSyntax MakeInterfaceProperty(PropertyDeclarationSyntax propertySyntax)
{
var accessors = propertySyntax.AccessorList.Accessors.Select(f => MakeInterfaceAccessor(f));
var syntaxList = new SyntaxList<AccessorDeclarationSyntax>();
syntaxList = syntaxList.AddRange(accessors);
var accessorList = propertySyntax.AccessorList.WithAccessors(syntaxList);
return propertySyntax.WithModifiers(new SyntaxTokenList()).WithAccessorList(accessorList);
}
示例7: RewriteFieldDeclaration
public ClassDeclarationSyntax RewriteFieldDeclaration(FieldDeclarationSyntax node)
{
var parent = node.Parent as ClassDeclarationSyntax;
var variables = node.Declaration.Variables;
var newmems = new SyntaxList<MemberDeclarationSyntax>();
var oldmems = parent.Members;
//var hits = variables.Where(x => this.annotationDCIs.Contains(SemanticModel.GetDeclaredSymbol(x).ToString()));
//if (hits.Any())
var hits = variables.Where(variable => SemanticModel.GetDeclaredSymbol(variable).ToString().Equals(AnnotationDCI));
if(hits.Any())
{
//RBLogger.Info("Got a hit");
oldmems = oldmems.Remove(node);
//var parent = node.Parent as ClassDeclarationSyntax;
//parent = parent.RemoveNode(node, SyntaxRemoveOptions.KeepDirectives | SyntaxRemoveOptions.KeepExteriorTrivia);
//parent = parent.RemoveNode(node, SyntaxRemoveOptions.KeepNoTrivia);
var oldmodifiers = node.Modifiers;
foreach (var variable in node.Declaration.Variables)
{
var varList = SyntaxFactory.SeparatedList<VariableDeclaratorSyntax>();
variables = variables.Add(variable);
var vardecl = SyntaxFactory.VariableDeclaration(node.Declaration.Type, varList);
var fielddecl = SyntaxFactory.FieldDeclaration(vardecl);
Contract.Assert(fielddecl != null);
fielddecl = fielddecl.AddModifiers(oldmodifiers.ToArray());
//if (hits.Contains(variable) && !oldmodifiers.Any(x => x.Text.Equals("readonly")))
if (hits.Contains(variable) && !oldmodifiers.Any(x => x.Equals(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword))))
{
//fielddecl = fielddecl.AddModifiers(SyntaxFactory.ParseToken(@"readonly"));
fielddecl = fielddecl.AddModifiers(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword));
fielddecl = fielddecl.WithTrailingTrivia(SyntaxFactory.Comment(Constants.String.Signature));
}
newmems = newmems.Add(fielddecl);
}
//newmems = newmems.AddRange(parent.Members);
newmems = newmems.AddRange(oldmems);
return parent.WithMembers(newmems);
}
return node.Parent as ClassDeclarationSyntax;
}