System.IO.FileSystemWatcher.RunningInstance.ReadName C# (CSharp) Méthode

ReadName() private méthode

Reads a UTF8 string from _buffer starting at the specified position and up to the specified length. Null termination is trimmed off (the length may include many null bytes, not just one, or it may include none).
private ReadName ( int position, int nameLength ) : string
position int
nameLength int
Résultat string
            private string ReadName(int position, int nameLength)
            {
                Debug.Assert(position > 0);
                Debug.Assert(nameLength >= 0 && (position + nameLength) <= _buffer.Length);

                int lengthWithoutNullTerm = nameLength;
                for (int i = 0; i < nameLength; i++)
                {
                    if (_buffer[position + i] == '\0')
                    {
                        lengthWithoutNullTerm = i;
                        break;
                    }
                }
                Debug.Assert(lengthWithoutNullTerm <= nameLength); // should be null terminated or empty

                return lengthWithoutNullTerm > 0 ?
                    Encoding.UTF8.GetString(_buffer, position, lengthWithoutNullTerm) :
                    string.Empty;
            }