Microsoft.R.Core.AST.AstNodeExtensions.GetEnclosingScope C# (CSharp) Method

GetEnclosingScope() public static method

Locates enclosing scope for a given node
public static GetEnclosingScope ( this node ) : IScope
node this
return IScope
        public static IScope GetEnclosingScope(this IAstNode node) {
            var gs = node as GlobalScope;
            if (gs != null) {
                return gs;
            }

            var root = node as AstRoot;
            if (root != null) {
                return root.Children.Count > 0 ? root.Children[0] as IScope : null;
            }

            var n = node.Parent;
            while (!(n is IScope) && n != null) {
                n = n.Parent;
            }
            return n as IScope;
        }
    }
AstNodeExtensions