Code/Editors/Attributes/NamespaceTitleAttribute.cs
using System;
using System.Linq;
namespace ExtendedBox.Editors.Attributes;
[AttributeUsage(AttributeTargets.All)]
public sealed class NamespaceTitleAttribute : TitleAttribute
{
public NamespaceTitleAttribute(Type type, int depth = -1, int skipLast = 0, string separator = " -> ") : base(GetTitle(type, depth, skipLast, separator))
{
}
private static string GetTitle(Type type, int depth, int skipLast, string separator)
{
var fullName = type.FullName;
if(fullName is null)
return string.Empty;
if(depth < 0)
depth = int.MaxValue - 1;
var splitted = fullName.Split('.').SkipLast(skipLast + 1).TakeLast(depth).Append(type.Name);
if(!splitted.Any())
return string.Empty;
return string.Join(separator, splitted);
}
}