Exemple #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());
        }
Exemple #2
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.GetHeapOffset() - 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.
            int resultIndex = lastFoundIndex + 1;
            return StringHandle.FromOffset(resultIndex).WithDotTermination();
        }
Exemple #3
0
        /// <summary>
        /// Two distinct namespace handles represent the same namespace if their full names are the same. This
        /// method merges builders corresponding to such namespace handles.
        /// </summary>
        private void PopulateNamespaceTable()
        {
            lock (_namespaceTableAndListLock)
            {
                if (_namespaceTable != null)
                {
                    return;
                }

                var namespaceBuilderTable = new Dictionary <NamespaceDefinitionHandle, NamespaceDataBuilder>();

                // Make sure to add entry for root namespace. The root namespace is special in that even
                // though it might not have types of its own it always has an equivalent representation
                // as a nil handle and we don't want to handle it below as dot-terminated synthetic namespace.
                // We use NamespaceDefinitionHandle.FromIndexOfFullName(0) instead of default(NamespaceDefinitionHandle) so
                // that we never hand back a handle to the user that doesn't have a typeid as that prevents
                // round-trip conversion to Handle and back. (We may discover other handle aliases for the
                // root namespace (any nil/empty string will do), but we need this one to always be there.
                NamespaceDefinitionHandle rootNamespace = NamespaceDefinitionHandle.FromIndexOfFullName(0);
                namespaceBuilderTable.Add(
                    rootNamespace,
                    new NamespaceDataBuilder(
                        rootNamespace,
                        rootNamespace.GetFullName(),
                        String.Empty));

                PopulateTableWithTypeDefinitions(namespaceBuilderTable);
                PopulateTableWithExportedTypes(namespaceBuilderTable);

                Dictionary <string, NamespaceDataBuilder> stringTable;
                MergeDuplicateNamespaces(namespaceBuilderTable, out stringTable);

                List <NamespaceDataBuilder> syntheticNamespaces;
                ResolveParentChildRelationships(stringTable, out syntheticNamespaces);

                var namespaceTable = new Dictionary <NamespaceDefinitionHandle, NamespaceData>();

                foreach (var group in namespaceBuilderTable)
                {
                    // Freeze() caches the result, so any many-to-one relationships
                    // between keys and values will be preserved and efficiently handled.
                    namespaceTable.Add(group.Key, group.Value.Freeze());
                }

                if (syntheticNamespaces != null)
                {
                    foreach (var syntheticNamespace in syntheticNamespaces)
                    {
                        namespaceTable.Add(syntheticNamespace.Handle, syntheticNamespace.Freeze());
                    }
                }

                _namespaceTable = namespaceTable;
                _rootNamespace  = namespaceTable[rootNamespace];
            }
        }
        public bool Equals(NamespaceDefinitionHandle handle, string value)
        {
            if (value == null)
            {
                Throw.ValueArgumentNull();
            }

            if (handle.HasFullName)
            {
                return _reader.StringStream.Equals(handle.GetFullName(), value, _reader.utf8Decoder);
            }

            return value == _reader.namespaceCache.GetFullName(handle);
        }
        public bool Equals(NamespaceDefinitionHandle handle, string value, bool ignoreCase)
        {
            if (value == null)
            {
                Throw.ValueArgumentNull();
            }

            if (handle.HasFullName)
            {
                return(_reader.StringHeap.Equals(handle.GetFullName(), value, _reader.UTF8Decoder, ignoreCase));
            }

            return(value == _reader.NamespaceCache.GetFullName(handle));
        }
Exemple #6
0
        public bool Equals(NamespaceDefinitionHandle handle, string value)
        {
            if (value == null)
            {
                ThrowValueArgumentNull();
            }

            if (handle.HasFullName)
            {
                return(reader.StringStream.Equals(handle.GetFullName(), value, reader.utf8Decoder));
            }

            return(value == reader.namespaceCache.GetFullName(handle));
        }
Exemple #7
0
        public string GetString(NamespaceDefinitionHandle handle)
        {
            if (handle.HasFullName)
            {
                return StringStream.GetString(handle.GetFullName(), utf8Decoder);
            }

            return namespaceCache.GetFullName(handle);
        }
        public string GetString(NamespaceDefinitionHandle handle)
        {
            if (handle.HasFullName)
            {
                return StringHeap.GetString(handle.GetFullName(), UTF8Decoder);
            }

            return NamespaceCache.GetFullName(handle);
        }
        public bool Equals(NamespaceDefinitionHandle handle, string value, bool ignoreCase)
        {
            if (value == null)
            {
                Throw.ValueArgumentNull();
            }

            if (handle.HasFullName)
            {
                return _reader.StringHeap.Equals(handle.GetFullName(), value, _reader.Utf8Decoder, ignoreCase);
            }

            return value == _reader.NamespaceCache.GetFullName(handle);
        }