/// <summary>
        /// Returns the name of the namespace to which the given position belongs.
        /// Returns null if the given file or position is null, or if no such namespace can be found
        /// (e.g. because the namespace name is invalid).
        /// </summary>
        public static string?TryGetNamespaceAt(this FileContentManager file, Position pos)
        {
            if (file == null || pos == null || !file.ContainsPosition(pos))
            {
                return(null);
            }
            var namespaces = file.GetNamespaceDeclarations();
            var preceding  = namespaces.TakeWhile(tuple => tuple.Item2.Start < pos);

            return(preceding.Any() ? preceding.Last().Item1 : null);
        }
예제 #2
0
        /// <summary>
        /// Returns the name of the namespace to which the given position belongs.
        /// Returns null if the given file or position is null, or if no such namespace can be found
        /// (e.g. because the namespace name is invalid).
        /// </summary>
        public static string TryGetNamespaceAt(this FileContentManager file, Position pos)
        {
            if (file == null || pos == null || !Utils.IsValidPosition(pos, file))
            {
                return(null);
            }
            var namespaces = file.GetNamespaceDeclarations();
            var preceding  = namespaces.TakeWhile(tuple => tuple.Item2.Start.IsSmallerThan(pos));

            return(preceding.Any() ? preceding.Last().Item1.Value : null);
        }