private static int IndexOfNodeInParent(SyntaxNode node) { if (node.Parent == null) { return(0); } var children = node.Parent.ChildNodesAndTokens(); var index = SyntaxNodeOrToken.GetFirstChildIndexSpanningPosition(children, ((CSharp.CSharpSyntaxNode)node).Position); for (int i = index, n = children.Count; i < n; i++) { var child = children[i]; if (child == node) { return(i); } } throw ExceptionUtilities.Unreachable; }