mirror of
https://github.com/lantean-code/qbtmud.git
synced 2025-10-23 04:52:22 +00:00
Add project files.
This commit is contained in:
54
Lantean.QBTMudBlade/Extensions.cs
Normal file
54
Lantean.QBTMudBlade/Extensions.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Lantean.QBTMudBlade;
|
||||
using Lantean.QBTMudBlade.Models;
|
||||
|
||||
namespace Lantean.QBTMudBlade
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public const char DirectorySeparator = '/';
|
||||
|
||||
public static string GetDirectoryPath(this string pathAndFileName)
|
||||
{
|
||||
return string.Join(DirectorySeparator, pathAndFileName.Split(DirectorySeparator)[..^1]);
|
||||
}
|
||||
|
||||
public static string GetDirectoryPath(this ContentItem contentItem)
|
||||
{
|
||||
return contentItem.Name.GetDirectoryPath();
|
||||
}
|
||||
|
||||
public static string GetFileName(this string pathAndFileName)
|
||||
{
|
||||
return pathAndFileName.Split(DirectorySeparator)[^1];
|
||||
}
|
||||
|
||||
public static string GetFileName(this ContentItem contentItem)
|
||||
{
|
||||
return contentItem.Name.GetFileName();
|
||||
}
|
||||
|
||||
public static string GetDescendantsKey(this string pathAndFileName, int? level = null)
|
||||
{
|
||||
var paths = pathAndFileName.Split(DirectorySeparator);
|
||||
var index = level is null ? new Index(1, true) : new Index(level.Value);
|
||||
return string.Join(DirectorySeparator, paths[0..index]) + DirectorySeparator;
|
||||
}
|
||||
|
||||
public static string GetDescendantsKey(this ContentItem contentItem, int? level = null)
|
||||
{
|
||||
return contentItem.Name.GetDescendantsKey(level);
|
||||
}
|
||||
|
||||
public static void CancelIfNotDisposed(this CancellationTokenSource cancellationTokenSource)
|
||||
{
|
||||
try
|
||||
{
|
||||
cancellationTokenSource.Cancel();
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
// disposed
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user