Repository: dotnet/runtime
File: src/libraries/System.Private.CoreLib/src/System/IO/DirectoryInfo.cs (C#)

Code before:
        public DirectoryInfo? Parent
        {
            get
            {
                // FullPath might end in either "parent\child" or "parent\child\", and in either case we want
                // the parent of child, not the child. Trim off an ending directory separator if there is one,
                // but don't mangle the root.
                string? parentName = Path.GetDirectoryName(PathInternal.IsRoot(FullPath.AsSpan()) ? FullPath : Path.TrimEndingDirectorySeparator(FullPath));
                return parentName != null ?
                    new DirectoryInfo(parentName, isNormalized: true) :
                    null;
            }
        }

        public DirectoryInfo CreateSubdirectory(string path)
        {
            ArgumentNullException.ThrowIfNull(path);

            if (PathInternal.IsEffectivelyEmpty(path.AsSpan()))
                throw new ArgumentException(SR.Argument_PathEmpty, nameof(path));
            if (Path.IsPathRooted(path))
                throw new ArgumentException(SR.Arg_Path2IsRooted, nameof(path));

            string newPath = Path.GetFullPath(Path.Combine(FullPath, path));

            ReadOnlySpan<char> trimmedNewPath = newPath.AsSpan().TrimEnd(Path.DirectorySeparator);
            ReadOnlySpan<char> trimmedCurrentPath = newPath.AsSpan().TrimEnd(Path.DirectorySeparator);

            // We want to make sure the requested directory is actually under the subdirectory.
            if (trimmedNewPath.StartsWith(trimmedCurrentPath, PathInternal.StringComparison)
                // Allow the exact same path, but prevent allowing "..\FooBar" through when the directory is "Foo"
                && ((trimmedNewPath.Length == trimmedCurrentPath.Length) || PathInternal.IsDirectorySeparator(newPath[trimmedCurrentPath.Length])))
            {
                FileSystem.CreateDirectory(newPath);
                return new DirectoryInfo(newPath);
            }

            // We weren't nested
            throw new ArgumentException(SR.Format(SR.Argument_InvalidSubPath, path, FullPath), nameof(path));
        }

        public void Create()
        {
            FileSystem.CreateDirectory(FullPath);
            Invalidate();
        }

        // Returns an array of Files in the DirectoryInfo specified by path
        public FileInfo[] GetFiles() => GetFiles("*", enumerationOptions: EnumerationOptions.Compatible);

        // Returns an array of Files in the current DirectoryInfo matching the

Review comment (suggestion):
```suggestion
            ReadOnlySpan<char> trimmedNewPath = newPath.AsSpan().TrimEnd(Path.DirectorySeparatorChar);
```

Sorry I didn't give you the correct full name of the property.

Code after:
        public DirectoryInfo? Parent
        {
            get
            {
                // FullPath might end in either "parent\child" or "parent\child\", and in either case we want
                // the parent of child, not the child. Trim off an ending directory separator if there is one,
                // but don't mangle the root.
                string? parentName = Path.GetDirectoryName(PathInternal.IsRoot(FullPath.AsSpan()) ? FullPath : Path.TrimEndingDirectorySeparator(FullPath));
                return parentName != null ?
                    new DirectoryInfo(parentName, isNormalized: true) :
                    null;
            }
        }

        public DirectoryInfo CreateSubdirectory(string path)
        {
            ArgumentNullException.ThrowIfNull(path);

            if (PathInternal.IsEffectivelyEmpty(path.AsSpan()))
                throw new ArgumentException(SR.Argument_PathEmpty, nameof(path));
            if (Path.IsPathRooted(path))
                throw new ArgumentException(SR.Arg_Path2IsRooted, nameof(path));

            string newPath = Path.GetFullPath(Path.Combine(FullPath, path));

            ReadOnlySpan<char> trimmedNewPath = Path.TrimEndingDirectorySeparator(newPath.AsSpan());

            // Trim any trailing separator, including from a root path for proper boundary checking.
            // TrimEndingDirectorySeparator does not trim the character from path roots.
            ReadOnlySpan<char> trimmedCurrentPath = FullPath.TrimEnd(Path.DirectorySeparatorChar);

            // We want to make sure the requested directory is actually under the subdirectory.
            if (trimmedNewPath.StartsWith(trimmedCurrentPath, PathInternal.StringComparison)
                // Allow the exact same path, but prevent allowing "..\FooBar" through when the directory is "Foo"
                && ((trimmedNewPath.Length == trimmedCurrentPath.Length) || PathInternal.IsDirectorySeparator(newPath[trimmedCurrentPath.Length])))
            {
                FileSystem.CreateDirectory(newPath);
                return new DirectoryInfo(newPath);
            }

            // We weren't nested
            throw new ArgumentException(SR.Format(SR.Argument_InvalidSubPath, path, FullPath), nameof(path));
        }

        public void Create()
        {
            FileSystem.CreateDirectory(FullPath);
            Invalidate();
        }

        // Returns an array of Files in the DirectoryInfo specified by path