本文整理汇总了C#中IfStatementSyntax.Ancestors方法的典型用法代码示例。如果您正苦于以下问题:C# IfStatementSyntax.Ancestors方法的具体用法?C# IfStatementSyntax.Ancestors怎么用?C# IfStatementSyntax.Ancestors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IfStatementSyntax
的用法示例。
在下文中一共展示了IfStatementSyntax.Ancestors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HasConflictingNames
static bool HasConflictingNames(SyntaxNodeAnalysisContext nodeContext, IfStatementSyntax ifElseStatement)
{
var block = ifElseStatement.Else.Statement as BlockSyntax;
if (block == null || block.Statements.Count == 0)
return false;
var member = ifElseStatement.Ancestors().FirstOrDefault(a => a is MemberDeclarationSyntax);
var priorLocalDeclarations = new List<string>();
foreach (var localDecl in member.DescendantNodes().Where(n => n.SpanStart < ifElseStatement.Else.SpanStart).OfType<LocalDeclarationStatementSyntax>()) {
foreach (var v in localDecl.Declaration.Variables)
priorLocalDeclarations.Add(v.Identifier.ValueText);
}
foreach (var sym in block.Statements)
{
var decl = sym as LocalDeclarationStatementSyntax;
if (decl == null)
continue;
if (priorLocalDeclarations.Contains(s => decl.Declaration.Variables.Any(v => v.Identifier.ValueText == s)))
return true;
}
return false;
}