Fix crash with empty fullname path

This commit is contained in:
2023-02-22 22:13:38 +01:00
parent 28bc479ee4
commit 3dccaa5243
8 changed files with 46 additions and 37 deletions

View File

@@ -7,11 +7,18 @@ public record FullName(string Path)
var pathParts = Path.TrimEnd(Constants.SeparatorChar).Split(Constants.SeparatorChar);
return pathParts.Length switch
{
> 1 => new(string.Join(Constants.SeparatorChar, pathParts.SkipLast(1))),
> 1 => CreateSafe(string.Join(Constants.SeparatorChar, pathParts.SkipLast(1))),
_ => null
};
}
public static FullName? CreateSafe(string? path)
{
if (string.IsNullOrWhiteSpace(path))
return null;
return new(path);
}
public string GetName()
=> Path.Split(Constants.SeparatorChar).Last();