예제 #1
0
        /// <summary>
        /// This will return a StringHandle for the simple name of a namespace name at the given segment index.
        /// If no segment index is passed explicitly or the "segment" index is greater than or equal to the number
        /// of segments, then the last segment is used. "Segment" in this context refers to part of a namespace
        /// name between dots.
        ///
        /// Example: Given a NamespaceDefinitionHandle to "System.Collections.Generic.Test" called 'handle':
        ///
        ///   reader.GetString(GetSimpleName(handle)) == "Test"
        ///   reader.GetString(GetSimpleName(handle, 0)) == "System"
        ///   reader.GetString(GetSimpleName(handle, 1)) == "Collections"
        ///   reader.GetString(GetSimpleName(handle, 2)) == "Generic"
        ///   reader.GetString(GetSimpleName(handle, 3)) == "Test"
        ///   reader.GetString(GetSimpleName(handle, 1000)) == "Test"
        /// </summary>
        private StringHandle GetSimpleName(NamespaceDefinitionHandle fullNamespaceHandle, int segmentIndex = Int32.MaxValue)
        {
            StringHandle handleContainingSegment = fullNamespaceHandle.GetFullName();

            Debug.Assert(!handleContainingSegment.IsVirtual);

            int lastFoundIndex = fullNamespaceHandle.Index - 1;
            int currentSegment = 0;

            while (currentSegment < segmentIndex)
            {
                int currentIndex = _metadataReader.StringStream.IndexOfRaw(lastFoundIndex + 1, '.');
                if (currentIndex == -1)
                {
                    break;
                }
                lastFoundIndex = currentIndex;
                ++currentSegment;
            }

            Debug.Assert(lastFoundIndex >= 0 || currentSegment == 0);

            // + 1 because lastFoundIndex will either "point" to a '.', or will be -1. Either way,
            // we want the next char.
            uint resultIndex = (uint)(lastFoundIndex + 1);

            return(StringHandle.FromIndex(resultIndex).WithDotTermination());
        }
예제 #2
0
파일: Heaps.cs 프로젝트: sandkum/corefx
        internal StringHandle GetNextHandle(StringHandle handle)
        {
            if (handle.IsVirtual)
            {
                return(default(StringHandle));
            }

            int terminator = this.Block.IndexOf(0, handle.Index);

            if (terminator == -1 || terminator == Block.Length - 1)
            {
                return(default(StringHandle));
            }

            return(StringHandle.FromIndex((uint)(terminator + 1)));
        }