本文整理汇总了C#中VariableDeclaratorSyntax.SepList1方法的典型用法代码示例。如果您正苦于以下问题:C# VariableDeclaratorSyntax.SepList1方法的具体用法?C# VariableDeclaratorSyntax.SepList1怎么用?C# VariableDeclaratorSyntax.SepList1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VariableDeclaratorSyntax
的用法示例。
在下文中一共展示了VariableDeclaratorSyntax.SepList1方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WithDeclarationMoved
private static BlockSyntax WithDeclarationMoved(BlockSyntax scope, LocalDeclarationStatementSyntax declaration, VariableDeclaratorSyntax v, ISemanticModel model, Assumptions assume, CancellationToken cancellationToken)
{
Func<SyntaxNode, bool> accesses = s => s.DescendantNodes()
.OfType<IdentifierNameSyntax>()
.Where(e => e.Identifier.ValueText == v.Identifier.ValueText)
.Where(e => model.GetSymbolInfo(e).Symbol == model.GetDeclaredSymbol(v))
.Any();
var isOutermostScope = scope.Statements.Contains(declaration);
var scopeStatements = isOutermostScope
? scope.Statements.SkipWhile(e => e != declaration).Skip(1).ToArray()
: scope.Statements.ToArray();
var statementAccesses = scope.Statements.Where(s => accesses(s)).ToArray();
if (statementAccesses.Length == 0) return null; //unused local, no change
var firstAccess = statementAccesses.FirstOrDefault();
var insertBeforeTarget = firstAccess;
if (v.Initializer != null && v.Initializer.Value.IsConst(model) != true) {
insertBeforeTarget = scopeStatements
.TakeWhile(e => e != firstAccess)
.SkipWhile(e => e.HasSideEffects(model, assume) == false)
.Append(firstAccess)
.FirstOrDefault();
}
if (statementAccesses.Length == 1 && insertBeforeTarget == firstAccess) {
if (firstAccess is BlockSyntax) {
var reducedScope = WithDeclarationMoved((BlockSyntax)firstAccess, declaration, v, model, assume, cancellationToken);
return scope.WithStatements(scope.Statements.Replace(firstAccess, reducedScope));
}
if (firstAccess is IfStatementSyntax) {
var s = (IfStatementSyntax)firstAccess;
if (!accesses(s.Condition)) {
if (!accesses(s.Statement) && s.Else.Statement is BlockSyntax) {
return scope.WithStatements(
scope.Statements.Replace(
s,
s.WithElse(
s.Else.WithStatement(
WithDeclarationMoved(
(BlockSyntax)s.Else.Statement,
declaration,
v,
model,
assume,
cancellationToken)))));
} else if (s.Statement is BlockSyntax && (s.Else == null || !accesses(s.Else.Statement))) {
return scope.WithStatements(
scope.Statements.Replace(
s,
s.WithStatement(
WithDeclarationMoved(
(BlockSyntax)s.Statement,
declaration,
v,
model,
assume,
cancellationToken))));
}
}
}
}
if (isOutermostScope && scopeStatements.TakeWhile(e => e != insertBeforeTarget).Where(e => !(e is LocalDeclarationStatementSyntax)).None())
return null; //minimal scope already
var newDeclaration = declaration.WithDeclaration(declaration.Declaration.WithVariables(v.SepList1()));
return scope.WithStatements(scope.Statements.InsertBefore(insertBeforeTarget, newDeclaration).List());
}