System.Resources.ResourceReader.AllocateStringForNameIndex C# (CSharp) Méthode

AllocateStringForNameIndex() private méthode

private AllocateStringForNameIndex ( int index, int &dataOffset ) : String
index int
dataOffset int
Résultat String
        private unsafe String AllocateStringForNameIndex(int index, out int dataOffset)
        {
            BCLDebug.Assert(_store != null, "ResourceReader is closed!");
            byte[] bytes;
            int byteLen;
            long nameVA = GetNamePosition(index);
            lock (this) {
                _store.BaseStream.Seek(nameVA + _nameSectionOffset, SeekOrigin.Begin);
                // Can't use _store.ReadString, since it's using UTF-8!
                byteLen = _store.Read7BitEncodedInt();

                if (_ums != null) {
                    if (_ums.Position > _ums.Length - byteLen)
                        throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ResourcesIndexTooLong", index));
                    
                    char* charPtr = (char*)_ums.PositionPointer;
                    String s = new String(charPtr, 0, byteLen/2);
                    _ums.Position += byteLen;
                    dataOffset = _store.ReadInt32();
                    return s;
                }

                bytes = new byte[byteLen];
                // We must read byteLen bytes, or we have a corrupted file.
                // Use a blocking read in case the stream doesn't give us back
                // everything immediately.
                int count = byteLen;
                while(count > 0) {
                    int n = _store.Read(bytes, byteLen - count, count);
                    if (n == 0)
                        throw new EndOfStreamException(Environment.GetResourceString("BadImageFormat_ResourceNameCorrupted_NameIndex", index));
                    count -= n;
                }
                dataOffset = _store.ReadInt32();
            }
            return Encoding.Unicode.GetString(bytes, 0, byteLen);
        }